的WebView NavigateWithHttpRequestMessage后不传递到Web服务器 [英] WebView NavigateWithHttpRequestMessage Post is not delivered to the webserver

查看:358
本文介绍了的WebView NavigateWithHttpRequestMessage后不传递到Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个后续问题,以用户@Kiewic的建议使用的WebView作出POST请求:的与在Windows商店应用的WebView一个信息发布的数据 - 使用C#

This is a follow-up question to the suggestion of user @Kiewic to make a post request using a webview: Post data with a request in a Windows Store app WebView - using C#

所以我使用此代码

// defined before: string uri, User user
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(uri));

request.Content = new HttpStringContent(
    String.Format(
        "language={0}&session_id={1}&user_id={2}",
        Text.GetLanguage(),
        user.session_id,
        user.user_id.ToString()
    ),
    Windows.Storage.Streams.UnicodeEncoding.Utf8,
    "application/x-www-form-urlencoded"
);

webView.NavigateWithHttpRequestMessage(request); // webView defined in xaml



提琴手显示我这个请求:

Fiddler shows me this request:

POST http://mobile.mysite.com/ HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US,en;q=0.8,de-CH;q=0.5,de;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; SMJB; WebView/2.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: mobile.mysyte.com
Content-Length: 101
Connection: Keep-Alive
Pragma: no-cache
Cookie: _ga=GA1.2.769009833.1387593479; PHPSESSID=nk6b04rb7d7vu4vmm2ish7l0o4

language=en&session_id=fhihferihguiegierewfrefghxrfer&user_id=1

网络服务器技术是PHP,所以我用这个代码打印帖子内容

The webserver technology is PHP, so I used this code to print the post content

<?php
var_dump($_POST);
?>



但结果却是一个空数组。那么,是我的错?

But the result is an empty array. So where is my mistake?

推荐答案

据微软的一名员工存在与设置请求内容的标题的错误。这应该意味着,没有什么是错我的第一邮编:
http://social.msdn.microsoft.com/Forums/windowsapps/en-US/7deaf4ba-611f-4957-af3c-9b2b2e1e1b8b/ webviewnavigatewithhttprequestmessage-设置的contentType?论坛= winappswithcsharp

According to a Microsoft employee there is a bug with setting the headers of the request content. This should mean that nothing is wrong with my code in the first post: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/7deaf4ba-611f-4957-af3c-9b2b2e1e1b8b/webviewnavigatewithhttprequestmessage-set-contenttype?forum=winappswithcsharp

这意味着你不能真正使用NavigateWithHttpRequest,你应该使用其他方法来发布数据。用户@Kiewic做这在Windows 8工作的建议太:
与在Windows商店应用的WebView一个信息发布的数据 - 使用C#

This means you cannot really use NavigateWithHttpRequest and you should use another approach to post data. User @Kiewic made a suggestion which works on Windows 8 too: Post data with a request in a Windows Store app WebView - using C#

这篇关于的WebView NavigateWithHttpRequestMessage后不传递到Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆