• <i id='F5eLV'><tr id='F5eLV'><dt id='F5eLV'><q id='F5eLV'><span id='F5eLV'><b id='F5eLV'><form id='F5eLV'><ins id='F5eLV'></ins><ul id='F5eLV'></ul><sub id='F5eLV'></sub></form><legend id='F5eLV'></legend><bdo id='F5eLV'><pre id='F5eLV'><center id='F5eLV'></center></pre></bdo></b><th id='F5eLV'></th></span></q></dt></tr></i><div id='F5eLV'><tfoot id='F5eLV'></tfoot><dl id='F5eLV'><fieldset id='F5eLV'></fieldset></dl></div>
    • <bdo id='F5eLV'></bdo><ul id='F5eLV'></ul>

      <tfoot id='F5eLV'></tfoot>
    1. <legend id='F5eLV'><style id='F5eLV'><dir id='F5eLV'><q id='F5eLV'></q></dir></style></legend>

      <small id='F5eLV'></small><noframes id='F5eLV'>

        带有自定义标头的 Android WebView 发布请求

        Android WebView Post Request with Custom Headers(带有自定义标头的 Android WebView 发布请求)
          1. <i id='FweeB'><tr id='FweeB'><dt id='FweeB'><q id='FweeB'><span id='FweeB'><b id='FweeB'><form id='FweeB'><ins id='FweeB'></ins><ul id='FweeB'></ul><sub id='FweeB'></sub></form><legend id='FweeB'></legend><bdo id='FweeB'><pre id='FweeB'><center id='FweeB'></center></pre></bdo></b><th id='FweeB'></th></span></q></dt></tr></i><div id='FweeB'><tfoot id='FweeB'></tfoot><dl id='FweeB'><fieldset id='FweeB'></fieldset></dl></div>
          2. <small id='FweeB'></small><noframes id='FweeB'>

          3. <tfoot id='FweeB'></tfoot>

                <bdo id='FweeB'></bdo><ul id='FweeB'></ul>

                    <tbody id='FweeB'></tbody>
                  <legend id='FweeB'><style id='FweeB'><dir id='FweeB'><q id='FweeB'></q></dir></style></legend>
                  本文介绍了带有自定义标头的 Android WebView 发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以看到 Android 文档中有两种不同的方法来发布数据和添加标题.

                  I could see there are two separate methods in Android docs to post the data and add the headers.

                  For setting Headers
                  public void loadUrl (String url, Map<String, String> additionalHttpHeaders)
                  
                  
                  For setting Post Data
                  public void postUrl (String url, byte[] postData)
                  

                  但我真正需要的是与标题一起发布数据.(意味着我想要一个同时完成这两个任务的方法?)

                  But what I really required is to post the data along with headers. ( Means I want a single method which does both the task ? )

                  谁能帮帮我.

                  谢谢:)

                  推荐答案

                  我最近遇到了同样的问题,几个小时后解决了.

                  I've bumped on same problem recently and after couple of hours solved it.

                  这是我的代码片段和一些注释:

                  Here is my code snippet with some comments:

                  HttpClient httpclient = new DefaultHttpClient();
                  
                  HttpPost httpPost = new HttpPost(getPostUrl());
                  
                  // example of adding extra header "Referer"
                  httpPost.addHeader("Referer", getReferer()); 
                  
                  ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                  
                  for (PostItem postItem : getPostItems()) { 
                      // key value post pairs
                      // add post parameters in array list
                      postParameters.add(new BasicNameValuePair(postItem.getKey(), postItem.getValue())); 
                  }
                  
                  HttpResponse response = null;
                  
                  try {
                      mWebView.getSettings().setJavaScriptEnabled(true);
                      httpPost.setEntity(new UrlEncodedFormEntity(postParameters));
                  
                      response = httpclient.execute(httpPost);
                  
                      BasicResponseHandler responseHandler = new BasicResponseHandler();
                      String htmlString = responseHandler.handleResponse(response);
                  
                      // important!! is to fill base url
                      mWebView.loadDataWithBaseURL(getPostUrl(), htmlString, "text/html", "utf-8", null); 
                  
                  } catch (Exception e){
                      // handle errors
                  }
                  

                  这篇关于带有自定义标头的 Android WebView 发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Cannot solve SonarQube error quot;Make this line start at column 3quot;(无法解决 SonarQube 错误“使此行从第 3 列开始)
                  SonarQube for multi module project for Android(适用于 Android 的多模块项目的 SonarQube)
                  How to integrate sonarqube in android studio?(如何在 android studio 中集成 sonarqube?)
                  Android What is the easist way Upgrade Database for existing DB(Android 为现有数据库升级数据库的简单方法是什么)
                  Updating SQLite database android(更新 SQLite 数据库 android)
                  Android: onUpgrade not calling at database upgrade(Android:onUpgrade 不在数据库升级时调用)
                    <bdo id='ZfRz7'></bdo><ul id='ZfRz7'></ul>

                    <small id='ZfRz7'></small><noframes id='ZfRz7'>

                    1. <tfoot id='ZfRz7'></tfoot>

                    2. <i id='ZfRz7'><tr id='ZfRz7'><dt id='ZfRz7'><q id='ZfRz7'><span id='ZfRz7'><b id='ZfRz7'><form id='ZfRz7'><ins id='ZfRz7'></ins><ul id='ZfRz7'></ul><sub id='ZfRz7'></sub></form><legend id='ZfRz7'></legend><bdo id='ZfRz7'><pre id='ZfRz7'><center id='ZfRz7'></center></pre></bdo></b><th id='ZfRz7'></th></span></q></dt></tr></i><div id='ZfRz7'><tfoot id='ZfRz7'></tfoot><dl id='ZfRz7'><fieldset id='ZfRz7'></fieldset></dl></div>
                        <tbody id='ZfRz7'></tbody>
                      <legend id='ZfRz7'><style id='ZfRz7'><dir id='ZfRz7'><q id='ZfRz7'></q></dir></style></legend>