서버가 연결을 닫는 지 여부는 클라이언트 요청이 연결을 닫으라는 요청 여부에 따라 달라집니다. 는 [각 요청의 요청 헤더의 마지막 줄이 있습니다 : 여기
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.data.Parameter;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.restlet.util.Series;
public class TestRestlet extends ServerResource {
@Get
public String getImpl(){
return "Sample Response Text\r\n";
}
}
그리고 내가 (만 텔넷을 사용하여) 리눅스 Section 명령 행에 무엇을 가지고 있습니다 : 여기
은 샘플 서버 코드 2
줄 바꿈] [혼란을 피하기 위해 다음, 요청 중 일부는 요청 바디를 포함하지 않습니다.]
[[email protected]]# telnet 172.16.101.34 6060
Trying 172.16.101.34...
Connected to win7comp01 (172.16.101.34).
Escape character is '^]'.
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=C2E77F4D0437E525A0FC66498EF09E8B; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:25:44 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Sample Response Text
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
Connection: Keep-Alive
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=1873DE26443F5DF62379B895AEA0F004; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:25:48 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Sample Response Text
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
Connection: close
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=43EC7C9AACC6C0CEF6FAC8F608B1D79C; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:25:57 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Connection: close
Sample Response Text
Connection closed by foreign host.
[[email protected]]# telnet 172.16.101.34 6060
Trying 172.16.101.34...
Connected to win7comp01 (172.16.101.34).
Escape character is '^]'.
GET /TestRestlet HTTP/1.0
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=2C879A91F2501DD9D3B39EF50C3F46CA; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:26:09 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Connection: close
Sample Response Text
Connection closed by foreign host.
[[email protected]]# telnet 172.16.101.34 6060
Trying 172.16.101.34...
Connected to win7comp01 (172.16.101.34).
Escape character is '^]'.
GET /TestRestlet
Sample Response Text
Connection closed by foreign host.
[[email protected]]#
을 위의 예에서, HTTP 연결의 여러 종류가 만들어집니다.
1 요청에 응답하여 :
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
[참고 : 라인 Host: 172.16.101.34:6060
2 \r\n
따른다 : \r\n\r\n
]
것은 :
는
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=C2E77F4D0437E525A0FC66498EF09E8B; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:25:44 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Sample Response Text
연결이 종료되지 아직 다른 요청을 보냅니다.
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=1873DE26443F5DF62379B895AEA0F004; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:25:48 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
가 여전히 연결이 종료되지 않습니다 응답을 얻을 수
. 그러나 제 3의 요청에
는 : 요청이 Connection: close
헤더가 포함되어 있기 때문에
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
Connection: close
연결이 폐쇄된다. 당신은 메시지를 표시 한 후 텔넷 종료를 볼 수 있습니다
1.An의 HTTP 1 : Connection closed by foreign host.
은 위에 주어진 예에서 2 개 샘플 요청 - 응답이 있습니다.0 요청 : 응답
GET /TestRestlet HTTP/1.0
: 표시 한 후
HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=2C879A91F2501DD9D3B39EF50C3F46CA; Path=/hotelSoft
Date: Wed, 31 Jul 2013 08:26:09 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.15
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Type: application/json;charset=UTF-8
Content-Length: 22
Connection: close
Sample Response Text
그리고 텔넷 종료 : 언급 HTTP 버전이없는 Connection closed by foreign host.
2.A 요청 :
GET /TestRestlet
및 응답 is : (헤더 없음)
,210
Sample Response Text
그리고 메시지와 함께 텔넷 종료 : Connection closed by foreign host.
이
결론 :
클라이언트/클라이언트 프로그램을 무엇이든간에
, 그것이 HTTP-1.0 요청을 보낼 수 있도록 또는 HTTP-1.1 요청 Connection: close
헤더.
자바에서는 이것을 달성 :
httpURLConnection.disconnect();
당신이 연결을 해제 할 수 있습니다 :이 같은 문이 경우
import java.net.HttpURLConnection;
import java.net.URL;
.
.
.
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://....").openConnection();
httpURLConnection.setRequestProperty("Connection","close");
// rest of the code here....
이 또한 확인.