我在写报文转发的时候,报了这个错误,Invalid Http response
请问是为什么?下面是代码
public static String postContent(String url, String content, String charSet) throws Exception {
OutputStream reqStream = null;
InputStream resStream = null;
URLConnection request = null;
String respText = null;
byte[] postData;
try {
postData = content.getBytes(charSet);
request = createRequest(url, "POST");
request.setRequestProperty("Content-type", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
request.setRequestProperty("Content-length", String.valueOf(postData.length));
request.setRequestProperty("Keep-alive", "ture");
reqStream = request.getOutputStream();
reqStream.write(postData);
reqStream.close();
ByteArrayOutputStream ms = null;
resStream = request.getInputStream(); //这一行报错了
ms = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int count;
while ((count = resStream.read(buf, 0, buf.length)) > 0) {
ms.write(buf, 0, count);
}
resStream.close();
respText = new String(ms.toByteArray(), charSet);
}
catch (Exception ex) {
throw ex;
}
finally {
close(reqStream);
close(resStream);
}
return respText;
}