C# Windows Phone 8.1带x-form-URL编码的网络视图导航

C# Windows Phone 8.1带x-form-URL编码的网络视图导航,c#,webview,windows-runtime,windows-phone-8.1,winrt-xaml,C#,Webview,Windows Runtime,Windows Phone 8.1,Winrt Xaml,我正在尝试使用WebView.NavigateWithHttpRequestMessage(请求)在Windows phone 8.1上发送POST x-www-form-urlencoded请求 我的代码是 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url)); List<KeyValuePair<string, string>> content = new

我正在尝试使用WebView.NavigateWithHttpRequestMessage(请求)在Windows phone 8.1上发送POST x-www-form-urlencoded请求

我的代码是

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
List<KeyValuePair<string, string>> content = new List<KeyValuePair<string, string>>();
content.Add(new KeyValuePair<string, string>("shop_id","123456"));
request.Content = new HttpStringContent(new HttpFormUrlEncodedContent(content).ToString(),Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
HttpRequestMessage请求=新的HttpRequestMessage(HttpMethod.Post,新的Uri(url));
列表内容=新列表();
添加(新的KeyValuePair(“店铺id”、“123456”);
request.Content=new-HttpStringContent(new-HttpFormUrlEncodedContent(Content).ToString(),Windows.Storage.Streams.unicodeincoding.Utf8,“application/x-www-form-urlencoded”);
Api返回我的状态,表示“错误的id_编号”,但我确信它是正确的,因为我尝试使用postman,它返回成功的状态代码。。。 我错过什么了吗?
谢谢:)

您必须将标题
内容类型设置为
应用程序/x-www-form-urlencoded
,请尝试以下代码:

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
request.Headers.TryAppendWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
request.Content = new HttpStringContent("shop_id=123456", UnicodeEncoding.Utf8);

我希望它能帮助您。

您必须将标题
内容类型设置为
应用程序/x-www-form-urlencoded
,请尝试以下代码:

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
request.Headers.TryAppendWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
request.Content = new HttpStringContent("shop_id=123456", UnicodeEncoding.Utf8);

我希望它能帮助你。

谢谢,但我已经试过了。我只是用字符串导航,我在其中放入html表单并将其发布到url:)您是否使用了NavigateToString WebView方法?在那之后,你是否点击了一个按钮,将表单发布到某个url?我添加了js来提交我的表单,所以我不必点击任何东西。它解决了你的问题吗?如果没有,您可以尝试通过
WebView.NavigateWithHttpRequestMessage(HttpRequestMessage)
发布内容。在这种情况下,您不必加载
WebView
两次。谢谢,但我已经试过了。我只是用字符串导航,我在其中放入html表单并将其发布到url:)您是否使用了NavigateToString WebView方法?在那之后,你是否点击了一个按钮,将表单发布到某个url?我添加了js来提交我的表单,所以我不必点击任何东西。它解决了你的问题吗?如果没有,您可以尝试通过
WebView.NavigateWithHttpRequestMessage(HttpRequestMessage)
发布内容。在这种情况下,您不必加载
WebView
两次。