Android通过HttpClient执行Http Post请求的代码

将写代码过程中常用的一些代码收藏起来,下面的资料是关于 Android通过HttpClient执行Http Post请求的代码,应该对小伙伴们也有用处。

public void postData() {

    HttpClient httpclient = new DefaultHttpClient();

    try {

        List nameValuePairs = new ArrayList(2);

        nameValuePairs.add(new BasicNameValuePair("id", "12345"));

        nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);


    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    }

}

你可能感兴趣的:(Android通过HttpClient执行Http Post请求的代码)