【问题标题】:Windows Phone 8.1 WebView navigation with x-form-urlencodedWindows Phone 8.1 WebView 导航与 x-form-urlencoded
【发布时间】:2015-11-27 03:55:46
【问题描述】:

我正在尝试在 Windows phone 8.1 上使用 WebView.NavigateWithHttpRequestMessage(request) 发送 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");

Api 返回代表“错误 id_number”的状态,但我确定它是正确的,因为我尝试使用邮递员,它返回成功的状态代码... 我错过了什么吗? 谢谢:)

【问题讨论】:

    标签: c# webview windows-runtime windows-phone-8.1 winrt-xaml


    【解决方案1】:

    你必须将 Header 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);
    

    希望对你有帮助。

    【讨论】:

    • 谢谢,但我已经尝试过了。我只是用我在其中放置 html 表单并将其发布到 url 的字符串导航 :)
    • 您是否使用了 NavigateToString WebView 方法?之后,您是否单击了将表单发布到某个 url 的按钮?
    • 我添加了js来提交我的表单,所以我不必点击任何东西
    • 它解决了你的问题吗?如果没有,您可以尝试通过WebView.NavigateWithHttpRequestMessage(HttpRequestMessage) 发布内容。在这种情况下,您不必加载WebView 两次。
    猜你喜欢
    • 2016-02-26
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多