gpt4 book ai didi

http - 向同一套接字中的服务器发送两个 HTTP 1.1 请求时出现问题

转载 作者:可可西里 更新时间:2023-11-01 17:03:48 26 4
gpt4 key购买 nike

<分区>

我正在尝试向同一个套接字中的服务器发送两个 HTTP 请求,我收到了第一个请求的响应,但第二个请求没有响应,我尝试使用相同或不同的缓冲区读取器和 BufferedWriter 发送它们,但我总是只对请求一个而不是两个响应都有响应。

我时间太紧了,请帮助我,谢谢你,

 Socket socket = new Socket(addr, port);
String strRequest1="myxmlRequest1....";
//send request
wr.write("POST / HTTP/1.1\r\n");
wr.write("Host: HOST\r\n");
wr.write("User-Agent: Java\r\n");
wr.write("Content-Length: " + strRequest1.length() + "\r\n");
wr.write("Content-Type: text/xml\r\n");
wr.write("Connection: Keep_alive\r\n\r\n");
wr.write(strRequest1 +"\r\n");
wr.flush();

// Get response
rd = new BufferedReader(new InputStreamReader(
socket.getInputStream(), "UTF8"));

System.out.println( "BufferedReader rd------------------------------>" + rd);
System.out.println( "readLine------------------------------>" + rd.toString());
while ((line = rd.readLine()) != null) {
System.out.println("output---------->" + output);
output = output + line + "\n";
}

System.out.println("taille response" + output.length());
// Request 2
String s2="myxmlRequest2...";
//send request
BufferedWriter wr2 = new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream(), "UTF8"));

System.out.println(s2);
wr2.write("POST / HTTP/1.1\r\n");
wr2.write("Host: HOST\r\n");
wr2.write("User-Agent: Java\r\n");
wr2.write("Content-Length: " + s2.length() + "\r\n");
wr2.write("Content-Type: text/xml\r\n");
wr2.write("Connection: Close\r\n\r\n");
wr2.write(s2 + "\r\n");
wr2.flush();

// get response
BufferedReader rd2 = new BufferedReader(new InputStreamReader(
socket.getInputStream(), "UTF8"));
output="";
while ((line = rd2.readLine()) != null) {
System.out.println("output2---------->" + output);
output = output + line + "\n";
}

System.out.println("s2 response" + output.length()+"s2"+output);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com