HttpClient

来源:互联网 发布:数控折弯机怎样编程 编辑:程序博客网 时间:2024/06/16 19:26
HttpClient client = new DefaultHttpClient();HttpPost post = new HttpPost(uri);List<NameValuePair>list = new ArrayList<NameValuePair>();NameValuePair pair = new BasicNameValuePair("name", "hh");list.add(pair);try {HttpEntity entity = new UrlEncodedFormEntity(list,HTTP.UTF_8);post.setEntity(entity);HttpResponse response = client.execute(post);if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){String result = EntityUtils.toString(entity, HTTP.UTF_8);}} catch (UnsupportedEncodingException e) {// TODO 自动生成的 catch 块e.printStackTrace();} catch (ClientProtocolException e) {// TODO 自动生成的 catch 块e.printStackTrace();} catch (IOException e) {// TODO 自动生成的 catch 块e.printStackTrace();}}

0 0