Forum Cross Platform with Xamarin

Webservice call is failing in xamarin cross platform

When we are calling to login webservices we are able to get response.
StatusCode: 200
response we are getting in json format as true.

When we are calling to other webservices which is sending json response. We are getting error

StatusCode: 400, 
ReasonPhrase: 'Bad Request', 
Version: 1.1, 
Content: System.Net.Http.StreamContent, Headers

We are using same code and services in both the case as below given:

     HttpClient client = new HttpClient();
            client.MaxResponseContentBufferSize = 256000;
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Autorization", username:password);
            client.DefaultRequestHeaders.Add("Content-Type", "application/json");

    var uri = new Uri("http://servername:portnumer/Myservicename.svc/Mymethodname"); 
                            //these services are working in restclient in mobile and desktop
    var response = await client.GetAsync(uri); 
            Debug.WriteLine(@"Web service request ended");
            if (response.IsSuccessStatusCode)
                var content = await response.Content.ReadAsStringAsync();
                Items = JsonConvert.DeserializeObject<List<MyClassName>>(content);

We are not able to find the root cause of the issue.
Any suggestions will be helpful.


  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @SwathiNagaraj - you incorrectly spelled Authorization in your header.

  • chin2chin2 INMember

    @AdamP said:
    @SwathiNagaraj - you incorrectly spelled Authorization in your header.

    Yes Thanks AdamP. I have corrected that but still facing the same issue and response.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @chin2 - Download and run some tests against your API. You will see the full response. The webservice should give you some more information along with its 400 bad request that will lead to the error.

Sign In or Register to comment.