자카르타 커먼즈 HttpClient에 문제가 있습니다.
내 스스로 작성한 HttpServer가 실제 요청을 받기 전에 하나의 요청이 완전히 비어 있습니다. 그것이 첫 번째 문제입니다.
첫 번째 문제가 해결되었습니다. 그것은 불필요한 URLConnection에 의한 것입니다! 번째 문제
때때로 요청 데이터가 HTTP 요청의 제 3 또는 제 4 라인 이후 끝난다 디버깅에
Jakarta Commons HttpClient에서 빈 요청을받는 이유는 무엇입니까?
POST/HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 127.0.0.1:4232
내가 축 TCPMonitor를 사용하고 있습니다. 거기에는 모든 일이 잘되지만 빈 요청이 있습니다. 스트림을 처리 할 수있는 새로운 방법을 찾을 수
StringBuffer requestBuffer = new StringBuffer();
InputStreamReader is = new InputStreamReader(socket.getInputStream(), "UTF-8");
int byteIn = -1;
do {
byteIn = is.read();
if (byteIn > 0) {
requestBuffer.append((char) byteIn);
}
} while (byteIn != -1 && is.ready());
String requestData = requestBuffer.toString();
:
어떻게 스트림을 처리합니다. 나는 모든 헤더 매개 변수를 읽고 'content-length'를 사용하여 게시물 데이터를 읽습니다.client.getParams().setSoTimeout(30000);
method = new PostMethod(url.getPath());
method.getParams().setContentCharset("utf-8");
method.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
method.addRequestHeader("Connection", "close");
method.setFollowRedirects(false);
byte[] requestXml = getRequestXml();
method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(requestXml)));
client.executeMethod(method);
int statusCode = method.getStatusCode();
당신의 사람에게 어떻게 이러한 문제 문제를 해결하는 아이디어 유무 : 내가 요청을 보내는 방법
InputStream is = mySocket.getInputStream();
if (is == null) {
return;
}
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
// Read the request line
// ...
// ...
// Parse the header
Properties header = new Properties();
if (st.hasMoreTokens()) {
String line = in.readLine();
while (line != null && line.trim().length() > 0) {
int p = line.indexOf(':');
header.put(line.substring(0, p).trim().toLowerCase(), line.substring(p + 1).trim());
line = in.readLine();
}
}
// If the method is POST, there may be parameters
// in data section, too, read it:
String postLine = "";
if (method.equalsIgnoreCase("POST")) {
long size = 0x7FFFFFFFFFFFFFFFl;
String contentLength = header.getProperty("content-length");
if (contentLength != null) {
try {
size = Integer.parseInt(contentLength);
} catch (NumberFormatException ex) {
}
}
postLine = "";
char buf[] = new char[512];
int read = in.read(buf);
while (read >= 0 && size > 0 && !postLine.endsWith("\r\n")) {
size -= read;
postLine += String.valueOf(buf, 0, read);
if (size > 0) {
read = in.read(buf);
}
}
postLine = postLine.trim();
decodeParms(postLine, parms);
}
?
알렉스
내가 처음 문제에 대해 잘 모르지만, 내가 두 번째 문제는이 때문입니다 생각
is.ready()를 제거하면 읽기 시간이 너무 길어집니다. 응답이 돌아올 때까지 약 20 초가 걸립니다. – alexvetter
'응답이 돌아 왔습니다'이라고 말하면 requestbuffer에 요청 XML을 읽는 데 20 초가 걸립니까? – simonlord
전체 요청은 xml 요청을 읽고 응답을 보내는 데 20 초 정도 걸립니다. – alexvetter