It is my first time to ask a question in here (I'm from Asia).
Platform:UWP 17632
IDE : Visual Studio 2017
Based on the reqiurement of the project, I need to post some information to a website.
I refer the answer about How to make HTTP POST web request Method A.
Here is my code:
public async void PostDataAsync(string pTemperture, string pHumidity, string pFireStatus, string pLightStatus, string pBodyStatus)
{
var values = new Dictionary<string, string>
{
{"count", "1" },
{"temperture_0", pTemperture },
{"Humidity_0", pHumidity },
{"FireStatus_0", pFireStatus },
{"LightStatus_0" ,pLightStatus},
{"BodyDetect_0", pBodyStatus }
};
var content = new FormUrlEncodedContent(values);
try
{
var response = await client.PostAsync("http://115.159.36.210/api/onehome/upload", content);//Here throw an exception
System.Diagnostics.Debug.WriteLine(response);
var responseString = response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine(responseString);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.HelpLink);
System.Diagnostics.Debug.WriteLine(ex.Message);
throw;
}
}
And then it throws an exception
“An error occurred while sending the request.”
in
var response = await client.PostAsync("http://115.159.36.210/api/onehome/upload", content);
I want to know why and gain the solution which can solve it.
I will be grateful if you can help me.