await httpClient.SendAsync(httpContent)
尽管我在代码/网址中没有发现错误,但没有响应,但它仍然挂起。请建议/帮助。
我的代码如下:
public async Task<string> Get_API_Result_String(string url, List<KeyValuePair<string, string>> parameters)
{
string res = "";
try
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
//Prepare url
Uri mainurl = new Uri(settings[FSAPARAM.UserSettingsParam.SERVERNAME].ToString());
Uri requesturl = new Uri(mainurl, url);
var httpClient = new HttpClient();
var httpContent = new HttpRequestMessage(HttpMethod.Post, requesturl);
// httpContent.Headers.ExpectContinue = false;
httpContent.Content = new FormUrlEncodedContent(parameters);
HttpResponseMessage response = await httpClient.SendAsync(httpContent);
var result = await response.Content.ReadAsStringAsync();
res = result.ToString();
response.Dispose();
httpClient.Dispose();
httpContent.Dispose();
}
catch (Exception ex)
{
Logger l = new Logger();
l.LogInfo("Get_API_Result_String: "+ url + ex.Message.ToString());
ex = null;
l = null;
}
return res;
}
在另一个类中调用它,如下所示:
NetUtil u = new NetUtil();
string result = await u.Get_API_Result_String(Register_API, values);
u = null;