I need to send a request in POST
to a php file through this application.
This code worked correctly in Windows Forms , but Xamarin is 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 send a POST request to a php file through Xamarin C #? If anyone can help me in this, I'm very grateful! Home Note: I already tested in windows forms and it worked without any problem, with this same file that is on our server.
I tried switching to HttpClient , continues to work in Windows Forms, but by xamarin just does not 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);
}
}