Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

404 error on PostAsync on web service

$
0
0

Hello. I have a web service developed in PHP which receives a POST request with JSON data and saves an entity. I test the web service with Postman and it works OK.

I have a Xamarin.Forms project where I call this webservice, and from my PCL class I have this code:

public async Task GuardarSolicitud(Solicitud solicitud)
        {
            string RestUrl = "http://routetoapi";
            var uri = new Uri(string.Format(RestUrl));

            var json = JsonConvert.SerializeObject(solicitud);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage response = null;
            response = await client.PostAsync(uri, content); //Previously I do client = new HttpClient();   client.MaxResponseContentBufferSize = 256000;

            if (response.IsSuccessStatusCode)
            {
                await DisplayAlert("Ok", "Ok", "Ok");
            }
            else
            {
                await DisplayAlert("Error", response.StatusCode.ToString(), "ok");
            }
        }

In the client.PostAsync() method I get response error 404 with this details:

{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Fri, 17 Mar 2017 17:29:34 GMT
Server: Apache
X-Powered-By: PHP/5.6.30
X-DEBUGKIT-ID: 8c05b10e-a153-4ca3-af6f-04c65381ccba
Keep-Alive: timeout=10, max=200
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
}}

What can I do? Thanks!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>