I use ABP as a server and a mobile app in Xamarin Forms.
In my Xamarin Forms I call through Flurl my api.
My api throws a UserFriendlyException. It works well through swagger UI browser.
But in my xamarin app it throws always as error 500 server FlurlHttpException.
And I can't access to my UserFriendlyException and message.
My swagger result when I call my api:
My call in my Xamarin Forms
var response = await webclient
.Request(LoginUrl)
.PostJsonAsync(loginModel)
.ReceiveJson<loginResultModel>();
It throws the flurlhttpexception. I should have the UserFriendlyException. This is the exception I have.
dynamic d = ex.GetResponseJson(); did the tricks.
thanks
Related
I am trying to setup development environment to integrate Google sign-in on Android using Web Authenticator in Xamarin Essentials.
In the Web API project, same AuthController is included described in this article. It is running on https://localhost:44311/api
To call the API from emulator, API url is referenced as https://10.0.2.2:43411/api as described in this article.
Now, I am able to call the API url using await WebAuthenticator.AuthenticateAsync(apiUrl, callbackUrl)
But, when API tries to invoke Google authentication via await Request.HttpContext.ChallengeAsync(scheme);, below error is returned from Google.
Error 400: invalid_request, device-id and device-name are required for
the private IP: https://10.0.2.2:4311/signin-google
As I understand, it is expecting request originated from the server instead of IP address like https://<servername>
Whole situation comes down to be able to access the webservice using name (or localhost) to be used in both emulator and Google redirect uri.
I'm new to laravel. I'm developing a web application using laravel 5.4. this app has an API also to communicate with mobile apps (these routs are inside routs/api).
My question is how to track token mismatch error and return a 401 with json msg. Now what's happening is whenever a request comes to api with invalid or no token, it's route back to login page.
This happens as the web app is configured to do so when user try to access a page without logging in.
I tried the exception/handle/render function but both exception are same type so couldn't differentiate.
(Both api and web app is in one laravel application)
We have an ASP.Net MVC web site that talks to a WebAPI service. This is authenticated at the application level by using application authentication in Azure AD.
This all works fine for GET and POST operations, but the same tokens don't work for PUT operations, is there any good reason for this?
EDIT - example of how we are calling the service.
We're using an HttpClient to make a call to the WebAPI
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
return await _httpClient.PutAsync(url, content);
Then we get back a HttpResponseMessage which has status code of Unauthorized.
We're not calling the Graph API directly but using the AAD instance to authenticate the calling of one service by another.
I am working with push notifications in windows phone. Notification channel uri is changing while re installing the app in the windows mobile. so there is a problem to send notification to the channel url.
By using web service i am storing the url in database.
I want to update the uri if it is changed using device id.
To do that, i have a WEB API method [HTTPGET] to check the deviceid availability in the database. It is developed to return True/False.
Now my question is, How can we communicate with the service and how can we handle the web api bool return type using C# in windows phone?
Thank You.
To communicate with the service with httpget request you have to use HttpClient class
Here how I do:
HttpClient client = new HttpClient();
string result=await client.GetStringAsync(url);
note that the event which call the web service must be declared async, because the httpclient is purely Asynchronous
I'm new to Web API and Windows Store App 8.1. I'm developing a Windows Store app that communicates to Web API. When I try to write the following code:
// server:53452/api/demo?ReportingMonth=10&ReportingYear=2013"
using (HttpClient httpClient = new HttpClient())
{
using (HttpResponseMessage response = await httpClient.GetAsync(new Uri("address")))
{
string result = await response.Content.ReadAsStringAsync();
var prodt = JsonConvert.DeserializeObject<ObservableCollection<Statuses>>(result);
return prodt;
}
}
I see that HttpClient is in both Windows.Web.Http and System.Net.Http. Which namespace should I use?
If I pick the System.Net.Http namespace, when I try to call my Web API, which is Windows Authenticate enabled, the cursor will not return back to the client, remaining in unknown state. Not sure about why I'm not receiving the response.
address = "abc.com:53452/api/demo?ReportingMonth=10&ReportingYear=2013"
using (HttpResponseMessage response = await httpClient.GetAsync(new Uri(address)))
If i use HttpClient from the Windows.Web.Http, windows store app asks me to enter credentials, and even though I entered my credentials correctly, system keeps prompting to enter the credentials. Can anyone explain why that happens?
Demystifying HttpClient APIs in the Universal Windows Platform
Which one should I use?
Since both of these APIs are available in UWP, the biggest question
for HTTP developers is which one to use in their app. The answer is
that it depends on a couple of factors:
Do you need to integrate with native UI for collecting user credentials, control HTTP cache read and write behavior; or pass in a
specific SSL client certificate for authentication?
If yes – then use Windows.Web.Http.HttpClient. At the time of this
writing, the Windows.Web.Http API provides greater control over HTTP
settings in UWP than the System.Net.Http API. In future versions, the
System.Net.Http API may also be enhanced to support these features on
UWP.
Do you intend to write cross-platform .NET code (across UWP/ASP.NET 5/iOS and Android)?
If yes – then use System.Net.Http API. This allows you to write code
that you can re-use on other .NET platforms such as ASP.NET 5 and .NET
Framework desktop applications. Thanks to Xamarin, this API is also
supported on iOS and Android, so you can reuse your code on these
platforms as well.
To perform HTTP authentication, instead of HttpClientHandler use HttpBaseProtocolFilter:
var filter = new HttpBaseProtocolFilter();
filter.ServerCredential = new
Windows.Security.Credentials.PasswordCredential(uri.ToString(), "foo", "bar");
var client = new HttpClient(filter);