我用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