post请求时2种传参方式
@Test
public void dopost(){
String httpurl = "https://jin.caimao.com/api/user/loginSalt";
Map<String,String> params = new HashMap<String,String>();
params.put("mobile", "XXXX");
params.put("login_pwd", "XXXX");
Editmappost(httpurl,params);
}
public void Editmappost(String url,Map<String,String> map){
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(url);
List<NameValuePair> pair = new ArrayList<NameValuePair>();
for(Map.Entry<String, String> entry:map.entrySet()){
pair.add(new BasicNameValuePair(entry.getKey(),entry.getValue().toString()));
}
try {
httppost.setEntity(new UrlEncodedFormEntity(pair)); try { CloseableHttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if(response.getStatusLine().getStatusCode()==200){
String stringentity = EntityUtils.toString(entity);
System.out.println(stringentity);
} } catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } @Test
public void dojsonpost(){
String apiurl = "http://baoxian.qa.ms.netease.com/vehicle";
String params = "{'license_no':'212','license_owner':'adfa','city_code':'21212'}";
JSONObject jsonobject = JSONObject.fromObject(params);
Editjsonpost(apiurl,jsonobject);
}
public void Editjsonpost(String url,Object json){
// JsonObject sjson = {"mobile":"XXXX","login_pwd":"XXXX"};
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(url); StringEntity stringEntity = new StringEntity(json.toString(),"UTF-8");
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json"); httppost.setEntity(stringEntity); try { CloseableHttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println(response.getStatusLine().getStatusCode());
if(response.getStatusLine().getStatusCode()==200){
String stringentity = EntityUtils.toString(entity);
System.out.println(stringentity);
} } catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }
post请求时2种传参方式的更多相关文章
- python 计算机发展史,线程Process使用 for循环创建 2种传参方式 jion方法 __main__的解释
########################总结################## #一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬 ...
- axios的各种传参方式
axios的各种传参方式 1. params方式 axios({ url: '/users', method: 'get', params: { id: '11111', name: '22222' ...
- 浅谈C++三种传参方式
浅谈C++三种传参方式 C++给函数传参中,主要有三种方式:分别是值传递.指针传递和引用传递. 下面通过讲解和实例来说明三种方式的区别. 值传递 我们都知道,在函数定义括号中的参数是形参,是给函数内专 ...
- Mybatis的几种传参方式,你了解吗?
持续原创输出,点击上方蓝字关注我 目录 前言 单个参数 多个参数 使用索引[不推荐] 使用@Param 使用Map POJO[推荐] List传参 数组传参 总结 前言 前几天恰好面试一个应届生,问了 ...
- PHP四种传参方式
test1界面: <html> <head> <title>testPHP</title> <meta http-equiv = "co ...
- Vue中router两种传参方式
Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...
- vue param和query两种传参方式
1.传参方式 query传参方式 this.$router.push({ path: "/home", query: {code:"123"} }) param ...
- vector作为参数的三种传参方式
c++中常用的vector容器作为参数时,有三种传参方式,分别如下(为说明问题,用二维vector): function1(std::vector<std::vector<int> ...
- vue的三种传参方式
<template> <div> <router-link :to="{'name':'x',params:{'type':'users'}}"> ...
随机推荐
- dubbo Forbid blacklist
http://www.jameswxx.com/dubbo/%E8%A7%A3%E5%86%B3dubbo%E9%97%AE%E9%A2%98%EF%BC%9Aforbid-consumer/
- C# 经典入门15章-TextBoxControl
第一步:设计界面如下:
- Html 中表单提交的一些知识总结——防止表单自动提交,以及submit和button提交表单的区别
转自:http://jackaudrey.blog.163.com/blog/static/1314217882010590041833/ 在页面中有多个input type="text&q ...
- MyEclipse9,MyEclipse10 安装ADT
Eclipse安装ADT 时步骤是开 Eclipse IDE,进入菜单中的 "Help" -> "Install New Software" ,点击Add ...
- HDU 1896 Stones(优先队列)
还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- UESTC 1222 Sudoku
爆搜即可 /* *********************************************** author : email :523689985@qq.com created tim ...
- USACO Section 1.3 Barn Repair 解题报告
题目 题目描述 某农夫有一个养牛场,所有的牛圈都相邻的排成一排(共有S个牛圈),每个牛圈里面最多只圈养一头牛.有一天狂风卷积着乌云,电闪雷鸣,把牛圈的门给刮走了.幸运的是,有些牛因为放假,所以没在自己 ...
- c# toolstrip控件怎么把左边的几个小点去掉??
选中你的toolstrip 然后属性属性中有个 GripStyle 设置Hidden
- Java中Calendar的用法
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Times } span.s1 { font: 13.0px Courier; backgro ...
- iOS之SDWebImage清理缓存
.找到 SDWebImage找到SDImageCache类 添加如下方法 - (float)checkTmpSize { float totalSize = 0; NSDirectoryEnumera ...