我在通用 Windows Phone 8.1 应用程序中遇到 httpclient 问题。 我一直在寻找,但在任何帖子中都没有有效的解决方案。
问题是,当我第一次调用 Web 服务时运行正常,但是当我第二次或第三次调用它时,出现错误 404。
除非您重新启动,否则应用程序不会再次运行。
我需要在 post 函数中发送该数据,因为我想发送格式化为字符串的 xml。
我的代码很简单:
var handler = new HttpClientHandler
{
Credentials = new
NetworkCredential("user", "pass", "domain")
};
using (var client = new HttpClient(handler))
{
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("XMLText", XMLText),
new KeyValuePair<string, string>("param1", "textParam1")
});
HttpResponseMessage response = new HttpResponseMessage();
response = await client.PostAsync(URL, formContent);
var responseString = response.Content.ReadAsStringAsync().Result;
MessageDialog msgbox = new MessageDialog(responseString);
await msgbox.ShowAsync();
}
我的网络服务更简单:
[WebMethod]
public String SetEnvioXML(string XMLText, string param1)
{
return XMLText;
}
有什么解决办法吗?
对不起我的英语,谢谢大家!
欢迎任何帮助!
最佳答案
尝试使用下面的代码可能会起作用, 首先尝试在 Google Rest Client 或 Post Man 上运行它
HttpRequestMessage httpRequest = new HttpRequestMessage();
httpRequest.Method = HttpMethod.Post;
httpRequest.RequestUri = URL;
httpRequest.Content = formContent ;
response =await client.SendAsync(httpRequest);
关于httpclient postasync windows phone 8.1通用app二次调用404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934803/