码迷,mamicode.com
首页 > Web开发 > 详细

发送post请求,回调时通过url传参

时间:2019-02-12 00:12:35      阅读:852      评论:0      收藏:0      [点我收藏+]

标签:task   code   val   str   app   new   com   rto   接口   

发送post请求,通过回调获取相应参数;在发送的url中添加参数,通过回调,获取其相应的参数值:

eg:

1、快递100发送post请求,进行订阅:

public class ExpressRegisterServiceImpl {

// 回调接口的地址
private static final String CALLBACKURL = "http://127.0.0.1/api/v2/expresscallback/kuaidi100/expressNotify";

public boolean registerToExpress100(ExpressOrderMapping expressOrderMapping) {

String mURL = CALLBACKURL + "?mappingid=" + expressOrderMapping.getId();//url获取参数
taskRequest.getParameters().put("callbackurl", mURL);

// create Map
Map<String, String> p = new HashMap<String, String>();
p.put("schema", schema);
p.put("param", JacksonHelper.toJSON(taskRequest));

String ret = HttpUtil.post(url, p);//发送post请求

}

}

2、订阅回调,获取url传参:

@RestController
@RequestMapping("api")
public class ExpressCallbackController {

@RequestMapping(value = "/v2/expresscallback/kuaidi100/expressNotify", method = RequestMethod.POST)
public Object expressNotify(HttpServletRequest request, HttpServletResponse response) {

String mappingid = request.getParameter("mappingid");

String content = request.getParameter("param");

}

}

3、通过postman验证:

技术图片

 

发送post请求,回调时通过url传参

标签:task   code   val   str   app   new   com   rto   接口   

原文地址:https://www.cnblogs.com/qqzhulu/p/10363623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!