Android Webview POST

前端 未结 4 1531
悲哀的现实
悲哀的现实 2020-11-28 05:22

I am trying to accomplish something quite simple, yet I have found no good documentation on this. I have a webView, and I need to load a page in it that requires POST data.

4条回答
  •  死守一世寂寞
    2020-11-28 06:05

    Try this:

    private static final String URL_STRING = "http://www.yoursite.com/postreceiver";
    
    public void postData() throws IOException, ClientProtocolException {  
    
         List nameValuePairs = new ArrayList();  
         nameValuePairs.add(new BasicNameValuePair("foo", "12345"));  
         nameValuePairs.add(new BasicNameValuePair("bar", "23456"));
    
         HttpClient httpclient = new DefaultHttpClient();  
         HttpPost httppost = new HttpPost(URL_STRING);  
         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
    
         HttpResponse response = httpclient.execute(httppost);  
    
    }
    

    I would recommend doing this as part of an AsyncTask and updating the WebView afterwards

提交回复
热议问题