JakartaCommonsHttpClientに問題があります。自分で作成したHttpServerが実際の要求を取得する前に、完全に空の要求が1つあります。それが最初の問題です。 最初の問題は解決されました。不要なURLConnectionが原因です! 2番目の問題は、httpリクエストの3行目または4行目以降にリクエストデータが終了する場合があることです。
POST / HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 127.0.0.1:4232
デバッグには、AxisTCPMonitorを使用しています。そこにはすべて問題ありませんが、空のリクエストです。
ストリームの処理方法:
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」を使用します。
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);
}
リクエストの送信方法:
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();
あなたの誰かがこれらの問題を問題を解決する方法を考えていますか?
アレックス