【发布时间】:2023-03-12 14:35:01
【问题描述】:
这是我第一次在这里提问(我来自亚洲)。
平台:UWP 17632
IDE:Visual Studio 2017
根据项目需求,我需要在网站上发布一些信息。
我参考了关于How to make HTTP POST web request方法A的答案。
这是我的代码:
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;
}
}
然后它抛出一个异常
“An error occurred while sending the request.”
在
var response = await client.PostAsync("http://115.159.36.210/api/onehome/upload", content);
我想知道为什么并获得可以解决它的解决方案。
如果您能帮助我,我将不胜感激。
【问题讨论】:
-
看看内部异常
-
@Kaushik Srinath 谢谢!!!我从来没有考虑过这个问题.......