华为摄像机 NAT 双向注册不能发送 post put请求的解决办法
技术博客 http://idea.coderyj.com/
1.不能发送post get请求的解决办法 在请求头中增加 Content-Length
String reqLineStr = method + " " + url + " HTTP/1.1\r\n";
HttpReqLineHelper reqLine = new HttpReqLineHelper(reqLineStr);
HttpHeadersHelper headers = new HttpHeadersHelper();
headers.addHeader("Accept", "*/*");
headers.addHeader("Host", remoteHost + ":" + remotePort);
// keep-alive
headers.addHeader("Connection", "keep-alive");
headers.addHeader("Content-Type", "application/json");
if (null != body){
// 请求体带参数的要添加长度
headers.addHeader("Content-Length", String.valueOf(body.length));
}
2.华为摄像头第三方告警不能解析请求头 Content-Type: application/
的解决办法
// 解决华为报警信息类型错误的问题 Content-Type: application/
@RequestMapping(value = "test1", method = RequestMethod.POST)
public Object test1(DeviceBean deviceBean, HttpServletRequest request) throws IOException {
// 从请求上下文里获取Request对象
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// IOUtils.copy(request.getInputStream(), baos);
ServletInputStream inputStream = request.getInputStream();
AlarmBean alarmBean = JSONObject.parseObject(inputStream, AlarmBean.class);
log.info("接收到告警参数--deviceBean " + deviceBean);
log.info("接收到告警参数" + alarmBean);
return "成功";
}