0
I need to submit a request on POST for a php file through this application. 
This code worked correctly on Windows Forms, however in Xamarin it’s not working...
public void testar()
        {
            try
            {
                string nome = txtName.Text;
                string URL = "http://www.italker.com.br/acoes/testphpcsharp.php/";
                WebClient webclient = new WebClient();
                NameValueCollection formData = new NameValueCollection();
                formData["nome"] = nome;
                string responsefromserver = Encoding.UTF8.GetString(webclient.UploadValues(URL, "POST", formData));
                webclient.Dispose();
            }
            catch (Exception ex)
            {
                    alertErrorShow(ex.ToString());
            }
        }
Here is the error message returned.
How do I submit a POST request to a php file through Xamarin C#? If anyone can help me with this, I am very grateful!
Note: I have tried it on windows Forms and it worked without any problem, with this same file that is on our server.
I tried to trade for Httpclient, keeps working on Windows Forms, but by Xamarin just doesn’t work, no error with nothing... Did I do something wrong?
 public void testar()
        {
            try
            {
                string nome = txtName.Text;
                string URL = "http://www.italker.com.br/acoes/testphpcsharp.php/";
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("nome", nome)
                });
                var myHttpClient = new HttpClient();
                var response = myHttpClient.PostAsync(URL, formContent);
                alertShow(response.ToString(), true);
            }
            catch (Exception ex)
            {
                alertShow(ex.ToString(), false);
            }
        }
Hi @Joao, try using Httpclient instead of Webclient..
– Marco Giovanni
How I would use Httpclient?
– João Pedro
I tried to change here but again, windows Forms was good, and Xamarin is still going wrong.
– João Pedro
The method
PostAsyncis asynchronous, hence the methodvoid testar()should beasync void testar()then call the asynchronous method as follows:await myHttpClient.PostAsync(URL, formContent)@Jonathan– rubStackOverflow