对接第三方接口,从请求体里获取到他们的数据
public static String getRequestPostData(HttpServletRequest request) {
int contentLength = request.getContentLength();
if (contentLength < 0) {
return null;
}
byte buffer[] = new byte[contentLength];
for (int i = 0; i < contentLength; ) {
int len = 0;
try {
len = request.getInputStream().read(buffer, i, contentLength - i);
} catch (IOException e) {
return null;
}
if (len == -1) {
break;
}
i += len;
}
try {
return new String(buffer, "utf-8");
} catch (UnsupportedEncodingException e) {
return null;
}
}