发送post请求,回调时通过url传参
Posted qqzhulu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送post请求,回调时通过url传参相关的知识,希望对你有一定的参考价值。
发送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传参的主要内容,如果未能解决你的问题,请参考以下文章