java + httpclient +post请求的示例解析
发布时间:2023-04-22 13:43:13 所属栏目:教程 来源:
导读:public void testMethodpost(){
//初始化http请求
CloseableHttpClient httpclient=HttpClientBuilder.create().build();
String url = "xxxxxxxxxxxxx";
//初始化http请求
HttpPost post=new HttpPost(url);
//初始化http请求
CloseableHttpClient httpclient=HttpClientBuilder.create().build();
String url = "xxxxxxxxxxxxx";
//初始化http请求
HttpPost post=new HttpPost(url);
|
public void testMethodpost(){ //初始化http请求 CloseableHttpClient httpclient=HttpClientBuilder.create().build(); String url = "xxxxxxxxxxxxx"; //初始化http请求 HttpPost post=new HttpPost(url); //设置请求头 post.setHeader("Content-Type","application/json;charset=UTF-8"); try { String paramJson="{\"userName\":\"xxxxxxx\",\"passWord\":\"JVGK+jDLU7\"}"; // JSONObject jsonObject = JSON.parSEObject(paramJson); // // System.out.println(jsonObject); // String param=JSON.toJSONString(jsonObject); // 提交参数发送请求 StringEntity requestEntity = new StringEntity(paramJson,"UTF-8"); post.setEntity(requestEntity); CloseableHttpResponse response=httpclient.execute(post); httpentity entity=response.getEntity(); String entityStr =EntityUtils.toString(entity,"UTF-8"); System.out.println(entityStr); //httpclient.close(); } catch (ClientProtocolException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } } (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
