发送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验证:

 

posted on 2019-02-11 23:22  qqzhulu  阅读(1436)  评论(0编辑  收藏  举报