troubleshooting Question

How to do HttpPost request via PostAsync to .NET webservice?

Avatar of tangteng78
tangteng78Flag for Malaysia asked on
.NET Programming* ASP.NET Core* Xamarin
3 Comments1 Solution14 ViewsLast Modified:
I have the error as attached when I'm trying to do a HttpPost request via PostAsync to a .NET webservice? It is just a simple POST request to update a recordset in the database via a passed parameter [id].

As a note, if I'd changed this request to HttpGet, the update worked as expected. This is to validate that there is no issue on the existing webservice.

The behind code that triggered by click event (Xamarin)
       public async void ClosedPO(object sender, EventArgs e)
            var payload = new Dictionary<string, int>
              {"id", 83832}

            string strPayload = JsonConvert.SerializeObject(payload);
           HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/json");

            Uri uri = new Uri("");
            var client = new HttpClient();
            var response = await client.PostAsync(uri, c);

            if (response.IsSuccessStatusCode)
                await DisplayAlert("SUCCESS!!", "", "OK");
                await DisplayAlert("FAIL", response.ToString(), "OK");

The code at webservice1.asmx
    Public Function PreorderClose(id As String) As Boolean
        If objProduct.changeProductStatus("preorderclosed", id) Then
            'Successfully updated
            '#Uncomment for production
            Return True
            Return False
        End If

    End Function

Web.config at our server
           <add name="HttpPost"/>
           <add name="HttpGet"/>

Error observed from my actual mobile phone when the button is clicked:

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros