Android通过HttpClient执行post请求详解编程语言

public void postData() { 
    // Create a new HttpClient and Post Header 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php"); 
  
    try { 
        // Add your data 
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
        nameValuePairs.add(new BasicNameValuePair("id", "12345")); 
        nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
  
        // Execute HTTP Post Request 
        HttpResponse response = httpclient.execute(httppost); 
          
    } catch (ClientProtocolException e) { 
        // TODO Auto-generated catch block 
    } catch (IOException e) { 
        // TODO Auto-generated catch block 
    } 
} 

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10681.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论