我用java編寫簡單的telnet應用程序,此應用程序發送請求(xml)和讀取響應。但是,當我發送超過1200字節的請求(從Java),然後我得到HTTP 500.如果我從命令行發送此命令,我得到HTTP 200(好)。在java中有最大大小限制嗎?我無法發送超過1200字節的請求從Java與Telnet {關閉}
我的代碼:
public static void main(String[] args) throws IOException {
Socket pingSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
pingSocket = new Socket("host", 4380);
out = new PrintWriter(pingSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(pingSocket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
return;
}
String newLine = "\n";
String header = "POST /path HTTP/1.1" + newLine
+ "Host: host:4380" + newLine
+ "Authorization: Basic cuyasdyq123ha123" + newLine
+ "Connection: close" + newLine
+ "SOAPAction: \"\"" + newLine
+ "Content-Type: text/xml; charset=utf-8" + newLine
+ "Content-Length: 2000" + newLine;
String request = "my xml data here";
System.out.println(header + request);
out.println(header);
out.println(request);
System.out.println(in.readLine());
System.out.println();
while (in.read() != -1) {
System.out.print((char) in.read());
}
out.close();
in.close();
pingSocket.close();
}
感謝所有幫助
你應該顯示你的代碼。 – home 2012-02-17 05:56:58
@home我添加了我的代碼 – totali 2012-02-17 06:06:01
當你得到一個HTTP 500時,檢查你的*服務器*日誌,看看那裏發生了什麼。 – Manish 2012-02-17 06:18:00