Windows Phone 8.1 WebView导航,带有x-form-urlencoded

本文关键字:带有 x-form-urlencoded 导航 WebView Phone Windows | 更新日期: 2023-09-27 18:24:47

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

我的代码是

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");

Api返回我的状态,代表"错误的id_number",但我确信这是正确的,因为我尝试过使用poster,它返回成功的状态代码。。。我是不是错过了什么?感谢:)

Windows Phone 8.1 WebView导航,带有x-form-urlencoded

您必须将标头Content-Type设置为application/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);

我希望它能帮助你。