记录http请求 body内容的添加和接收
来源:互联网 发布:淘宝散片cpu去哪家买 编辑:程序博客网 时间:2024/06/08 11:25
//http请求 body内容添加
public static void do_json_req(){
HttpPost request = new HttpPost("http://localhost:8080/DSQ_Payment/uccb.do");
JSONObject param_data = new JSONObject();
param_data.put("orderId", "abcf1330");
param_data.put("gameId", 123);
param_data.put("accountId", "12221222211123");
param_data.put("creator", "JY");
param_data.put("payWay", 1);
param_data.put("amount", "100.00");
param_data.put("callbackInfo", "custominfo=xxxxx#user=xxxx");
param_data.put("orderStatus", "S");
param_data.put("failedDesc", "");
param_data.put("cpOrderId", "1234567");
JSONObject param = new JSONObject();
param.put("ver", "2.0");
param.put("data", param_data);
param.put("sign", "6362e564f832d2e8bbcbd50e75409d47");
// 绑定到请求Entry
StringEntity se;
try {
se = new StringEntity(param.toString());
request.setEntity(se);
// 发送请求
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
String retSrc = EntityUtils.toString(httpResponse.getEntity());
// 生成 JSON 对象
// JSONObject result = new JSONObject( retSrc);
// String token = result.get("token");
System.out.println(retSrc);
} catch (Exception e) {
e.printStackTrace();
}
//http body内容接收
public String ucCB(HttpServletRequest req){
UcpayCBVO uccbvo=null;
String ret = "error....";
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(req.getInputStream()));
String line = "";
String reqstr = "";
while((line=bf.readLine()) != null){
reqstr += line;
}
if(null != reqstr && !"".equals(reqstr)){
Map<String, Object> f_map =PayUtil.jsonToMap(reqstr);
Map<String, Object> map_json =(Map<String, Object>)f_map.get("data");
map_json.put("ver", f_map.get("ver"));
map_json.put("sign", f_map.get("sign"));
reqstr=PayUtil.ObjectToJsonStr(map_json);
uccbvo = (UcpayCBVO) PayUtil.jsonToObject(reqstr, UcpayCBVO.class);
ret = ucService.callBackPayCenter(uccbvo);
}
log.debug("uccb: " + PayUtil.ObjectToJsonStr(uccbvo));
} catch (Exception e) {
log.error("uc cb error!", e);
}
log.debug("uc cb ret=" + ret + "; orderid=" + uccbvo.getOrderId());
return ret;
}
不是全部的代码,留下主要的两部分,给以后做参考~~
- 记录http请求 body内容的添加和接收
- http请求的header body
- java接收http请求body中的json数据
- Http Post请求 带Header和Body
- Java Http请求工具类和接收请求的方法
- Http post请求 entity body的格式
- HttpServletRequest中读取HTTP请求的body
- 关于http请求body
- howto使用http接收和发送简单的xml请求
- HTTP发送请求和接收响应的整个流程
- 简述HTTP 协议接收Message Body的方式
- curl外另外一种发送http请求和接收http请求的方式
- 获得WebAPI原始POST请求BODY的JSON内容
- Java如何从HttpServletRequest中读取HTTP请求的body
- Java如何从HttpServletRequest中读取HTTP请求的body
- Java如何从HttpServletRequest中读取HTTP请求的body
- Java如何从HttpServletRequest中读取HTTP请求的body
- Java如何从HttpServletRequest中读取HTTP请求的body
- svn 合并tag
- Linux的TUN/TAP编程
- SQL学习笔记10——表连接查询
- centos chmod改变文件权限
- 将SELinux的安全特性加入安卓
- 记录http请求 body内容的添加和接收
- JavaWeb前端分页显示方法
- 查看VS2013中项目的宏定义
- android Preference之android:dependency
- Retrofit2打印 网络请求日志
- centos6.5启动报错处理
- 设置webview禁用长按弹出框
- Instanceof关键字
- 找出缺失的整数