httpclient postasync windows phone 8.1通用app二次调用404错误

标签 http post windows-phone-8.1 httpclient universal

我在通用 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/

相关文章:

audio - 有没有办法选择我使用Windows Phone 8.1从OneNote生成的音频文件?

windows - 查询 http header 时出现错误 ERROR_WINHTTP_HEADER_NOT_FOUND

android - apache.http 和 apache.commons.httpclient 库有什么区别?

php - 从 iOS 模拟器向本地主机发送 Post 请求

windows-runtime - 设置 Windows Phone 8.1/WinRT AppBarButton 样式

c# - Windows Phone 8.1 中的 BackButtonPressed 问题?

http - 使用 http-conduit 在 Haskell 中发送 HTTP/POST 的基本方法

java - 在服务器上运行 struts2 应用程序时出现 http 状态 404

python - 使用 Python Requests 在 postman 中做 post 请求

java - Spring发送和获取文件的正确方式