Sample http range request session - http

Is it possible to show me a sample http session with range requests.
I mean what would be the request and response headers?

The following exchange is between Chrome and a static web server, retrieving an MP4 video.
Initial request - for the video. Note the Accept-Ranges response header to indicate the server has range header support:
GET /BigBuckBunny_320x180.mp4
Cache-Control: max-age=0
Connection: keep-alive
Accept-Language: en-GB,en-US,en
Host: localhost:8080
Range:
Accept: text/html,application/xhtml+xml,application/xml,*/*
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ...
Accept-Encoding: gzip,deflate,sdch
Accept-Charset: ISO-8859-1,utf-8,*
200 OK
Content-Type: video/mp4
Connection: keep-alive
Last-Modified: Wed,14 Dec 2011 15:50:59 GMT
ETag: A023EF02BD589BC472A2D6774EAE3C58
Transfer-Encoding:
Content-Length: 64657027
Accept-Ranges: bytes
Server: Brisket/1.0.1
Date: Wed,14 Dec 2011 16:11:24 GMT
Range header in previous response detected - subsequent request with open-ended range to confirm support. Response returns a 206 status and Content-Range header to indicate the bytes present in the response body:
GET /BigBuckBunny_320x180.mp4
Connection: keep-alive
Accept-Language: en-GB,en-US,en
Host: localhost:8080
Range: bytes=0-
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ...
Referer: http://localhost:8080/BigBuckBunny_320x180.mp4
Accept-Encoding: identity
Accept-Charset: ISO-8859-1,utf-8,*
206 Partial Content
Content-Type: video/mp4
Connection: keep-alive
Last-Modified: Wed,14 Dec 2011 15:50:59 GMT
ETag: A023EF02BD589BC472A2D6774EAE3C58
Transfer-Encoding:
Content-Length: 64657027
Accept-Ranges: bytes
Server: Brisket/1.0.1
Date: Wed,14 Dec 2011 16:11:25 GMT
Content-Range: bytes 0-64657026/64657027
Subsequent range request to capture the end of the file (probably to capture trailing metadata):
GET /BigBuckBunny_320x180.mp4
Connection: keep-alive
Accept-Language: en-GB,en-US,en
Host: localhost:8080
Range: bytes=64312833-64657026
Accept: */*
If-Range: A023EF02BD589BC472A2D6774EAE3C58
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ...
Referer: http://localhost:8080/BigBuckBunny_320x180.mp4
Accept-Encoding: identity
Accept-Charset: ISO-8859-1,utf-8,*
206 Partial Content
Content-Type: video/mp4
Connection: keep-alive
Last-Modified: Wed,14 Dec 2011 15:50:59 GMT
ETag: A023EF02BD589BC472A2D6774EAE3C58
Transfer-Encoding:
Content-Length: 344194
Accept-Ranges: bytes
Server: Brisket/1.0.1
Date: Wed,14 Dec 2011 16:11:25 GMT
Content-Range: bytes 64312833-64657026/64657027
User clicks in the video progress bar beyond the downloaded range - a range request is issued to begin playing from the selected position:
GET /BigBuckBunny_320x180.mp4
Connection: keep-alive
Accept-Language: en-GB,en-US,en
Host: localhost:8080
Range: bytes=1073152-64313343
Accept: */*
If-Range: A023EF02BD589BC472A2D6774EAE3C58
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 ...
Referer: http://localhost:8080/BigBuckBunny_320x180.mp4
Accept-Encoding: identity
Accept-Charset: ISO-8859-1,utf-8,*
206 Partial Content
Content-Type: video/mp4
Connection: keep-alive
Last-Modified: Wed,14 Dec 2011 15:50:59 GMT
ETag: A023EF02BD589BC472A2D6774EAE3C58
Transfer-Encoding:
Content-Length: 63240192
Accept-Ranges: bytes
Server: Brisket/1.0.1
Date: Wed,14 Dec 2011 16:11:25 GMT
Content-Range: bytes 1073152-64313343/64657027

Related

How to generate Python XHR Request in requests.post()

I am trying to get info from a website using AJAX. The Website showing different size for perfume and basically, the price would change when selecting different size.
I checked chrome Network Tab and found it's a XHR request, but looking at the request head I have no idea how to generate the same headers and data with the Requests package.
This is how my code currently looks like:
import requests
url = "https://www.beautyfresh.com/uc_aac"
session = requests.Session()
data = {"attributes[Size]":"100ml"} # I want to get the price for 100ml
headers = {"Referer": "https://www.beautyfresh.com/product/fragrance/men/perfume-fragrance/women/perfume-men/fragrance/perfume/jo-malone-orange-blossom-cologne",}
r = session.post(url,headers=headers,data=data)
print(r.text)
The General information under Chrome Network tab is
Request URL: https://www.beautyfresh.com/uc_aac
Request Method: POST
Status Code: 200 OK
Remote Address: 103.255.250.100:443
Referrer Policy: no-referrer-when-downgrade
The Response Headers is
HTTP/1.1 200 OK
date: Fri, 18 Dec 2020 02:01:05 GMT
expires: Sun, 19 Nov 1978 05:00:00 GMT
x-site: beautyfresh
x-url: /uc_aac
last-modified: Fri, 18 Dec 2020 02:01:05 GMT
x-backend-server: web4
content-type: application/json
x-varnish: 700512226
age: 0
via: 1.1 varnish (Varnish/6.0)
x-cache: MISS
cache-control: Cache-Control: store, no-cache, must-revalidate
accept-ranges: bytes
content-length: 2193
The Request Headers is
POST /uc_aac HTTP/1.1
Host: www.beautyfresh.com
Connection: keep-alive
Content-Length: 164
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Origin: https://www.beautyfresh.com
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://www.beautyfresh.com/product/fragrance/men/perfume-fragrance/women/perfume-men/fragrance/perfume/jo-malone-orange-blossom-cologne
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: has_js=1; SESSc5f2026dce40de323b60d32130e6ce0b=n7tr5e2fsragf1js6garc6u06n; _ga=GA1.2.959938064.1608216963; _gid=GA1.2.1979056032.1608216963; _v1EmaticSolutionsUTMData=%7B%22utm_source%22%3A%22%22%2C%22utm_medium%22%3A%22%22%2C%22utm_campaign%22%3A%22%22%7D; _fbp=fb.1.1608216963288.1600789170; _v1EmaticSolutionsBye=%7B%2228732%22%3A%7B%2230038%22%3A%7B%22dont_show_till%22%3A%222020-12-20%22%2C%22loop%22%3A1%7D%7D%2C%2228739%22%3A%7B%2230045%22%3A%7B%22dont_show_till%22%3A%222020-12-20%22%2C%22loop%22%3A1%7D%7D%7D; _v1EmaticSolutionsEI=%7B%22c_28739_1%22%3A%5B1%2C1608216997180%2C33181%5D%2C%22c_28732_2%22%3A%5B1%2C1608216969616%2C0%5D%7D; _v1EmaticSolutions=%5B%22fc5d18b3-4077-11eb-970e-0242ac160003%22%2C1608217230870%2C%5B%22IMG%22%2C%22%22%2C1%2C%22glasshouse_fragrances_amalfi_coast_sea_candle_350gr.jpg%22%5D%5D; __atuvc=8%7C51; __atuvs=5fdc0d5961186ea4000; _gat=1; _dc_gtm_UA-63339192-1=1
And Form Data shows:
attributes%5BSize%5D=100ml&nid=2905&qty=1&form_build_id=form-991e88780c30fdf883375a36a986b550&form_id=uc_product_add_to_cart_form_2905&product-nid=2905&aac_nid=2905
I don't actually know how to construct my request so it can be successfully posted to the server the get the proper response. It should return the price for "100ml", but currently my code get nothing.
Thank you so much for any help!
You are missing some information in your data. To receive a response, try adding "aac_nid": "2905" to your data when sending the post request:
import requests
headers = {
"Referer": "https://www.beautyfresh.com/product/fragrance/men/perfume-fragrance/women/perfume-men/fragrance/perfume/jo-malone-orange-blossom-cologne",
}
data = {"attributes[Size]": "30ml", "aac_nid": "2905"}
response = requests.post(
"https://www.beautyfresh.com/uc_aac", headers=headers, data=data
)
>>> print(response.content)
b'{"nid":"2905","model":"690251006564","replacements":{"sellprice":"<div class=\\"product-info sellprice\\"><div class=\'retail_price\'>City Price: <div class=\'product-info retail_price\'><span class=\'uc-price\'>S$110.00<\\/span><\\/div><\\/div>\\r\\n <div class=\'promoprice\'>Our Price: <div class=\'product-info sellprice1\'><span class=\'uc-price\'>S$89.00<\\/span><\\/div><\\/div><\\/div>","model":"<div class=\\"model\\"><span class=\\"label\\">Product Code: <\\/span>690251006564<\\/div>"},"form":"<form action=\\"\\/uc_aac\\" accept-charset=\\"UTF-8\\" method=\\"post\\" id=\\"uc-product-add-to-cart-form\\" class=\\" uc-aac-cart\\">\\n<div><div class=\'attributes\'><div class=\\"form-item\\" id=\\"edit-attributes-Size-wrapper\\">\\n <label for=\\"edit-attributes-Size\\">Size <span class=\\"form-required\\" title=\\"This field is required.\\">*<\\/span><\\/label>\\n <select name=\\"attributes[Size]\\" class=\\"form-select required chosen-widget\\" data-name=\\"Size\\" id=\\"edit-attributes-Size\\" ><option value=\\"30ml\\" selected=\\"selected\\">30ml<\\/option><option value=\\"100ml\\">100ml<\\/option><\\/select>\\n<\\/div>\\n<\\/div><input type=\\"hidden\\" name=\\"nid\\" id=\\"edit-nid\\" value=\\"2905\\" \\/>\\n<div class=\\"form-item\\" id=\\"edit-qty-wrapper\\">\\n <label for=\\"edit-qty\\">Qty <\\/label>\\n <input type=\\"text\\" maxlength=\\"3\\" name=\\"qty\\" id=\\"edit-qty\\" size=\\"5\\" value=\\"1\\" class=\\"form-text textfield\\" \\/>\\n<\\/div>\\n<input type=\\"hidden\\" name=\\"form_build_id\\" id=\\"form-b7adf002178f04ed96377894057352a2\\" value=\\"form-b7adf002178f04ed96377894057352a2\\" \\/>\\n<input type=\\"hidden\\" name=\\"form_id\\" id=\\"edit-uc-product-add-to-cart-form\\" value=\\"uc_product_add_to_cart_form\\" \\/>\\n<input type=\\"hidden\\" name=\\"aac_nid\\" id=\\"edit-aac-nid\\" value=\\"2905\\" \\/>\\n<div class=\'leadtime_message\' style=\'margin-bottom:1em;\'><p>Delivers in 1-3 working days<\\/p><\\/div><input type=\\"submit\\" name=\\"op\\" id=\\"edit-submit-2905\\" value=\\"Add to Cart\\" class=\\"notranslate form-submit node-add-to-cart primary\\" \\/>\\n\\n<\\/div><\\/form>\\n"}'
To get the price, try searching for it with the help of the built-in re (regex) module:
import re
prices = re.findall(r"'uc-price\\'>S(\$\d.*?)<", str(response.content))
print("Original Price:", prices[0])
print("Our Price:", prices[1])
Output:
Original Price: $110.00
Our Price: $89.00

206 Partial Content does not accept data from server

I'm trying return video partially, using 206 Partial Content, I transfer all the headers correctly, but the request passes only 4kb, but if I answer 200 OK, the video will work, what could be the problem?
(If I answer 200 OK, then I can't rewind the video)
Type: Document
Request:
GET / HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
DNT: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: ru,en;q=0.9
Response:
HTTP/1.1 200 OK
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Mon, 11 Mar 2019 19:03:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Type: video/mp4; charset=utf-8
Date: Mon, 11 Mar 2019 19:03:02 GMT
Content-Length: 16766763
Keep-Alive: timeout=15,max=100
=============================================
Type: Media
Request:
GET / HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
DNT: 1
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
Accept: */*
Referer: http://127.0.0.1:8080/
Accept-Language: ru,en;q=0.9
Range: bytes=0-
Response:
HTTP/1.1 206 Partial Content
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Mon, 11 Mar 2019 19:03:02 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Accept-Ranges: bytes
Content-Type: video/mp4; charset=utf-8
Date: Mon, 11 Mar 2019 19:03:02 GMT
Keep-Alive: timeout=15,max=100
Content-Range: bytes 0-29593599/29593600
Content-Length: 29593600
The problem was in localhost, everything works on server, thanks :)

JSON-Encoded POST/PATCH data in R

I want to make a POST to a webserver running a Rails application (I didn't develop the application, I just need to post to it) and I've been trying to use R with little success.
I've been doing this with httr and jsonlite:
install.packages("httr");
install.packages("jsonlite")
library(jsonlite)
library("httr");
url = "http://192.168.0.168:3000/api/styles";
b <- list(name="Lorem", description="Ipsum");
POST(url,body=b,encode='json');
Which nets me the result of actually being able to post but renders a warning from Rails:
Response [http://192.168.0.168:3000/api/styles/18]
Date: 2015-11-06 13:20
Status: 411
Content-Type: text/html; charset=ISO-8859-1
Size: 307 B
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Length Required</TITLE></HEAD>
<BODY>
<H1>Length Required</H1>
WEBrick::HTTPStatus::LengthRequired
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) at
192.168.0.168:3000
All other attempts at using other encoding options or content-type headers have given me a warning of 422 Unprocessable Entity.
I have however been successful at doing this in Python with this snippet:
import requests
url = "http://192.168.0.168:3000/api/styles"
payload = {'name': 'Lorem', 'description': 'Ipsum'}
r = requests.post(url, json=payload)
Can anyone shine a light on what am I doing wrong in the R request?
Update 1: I've added the Verbose Option and the output
-> POST /api/styles HTTP/1.1
-> Host: 192.168.0.168:3000
-> User-Agent: libcurl/7.43.0 r-curl/0.9.3 httr/1.0.0
-> Accept-Encoding: gzip, deflate
-> Cookie: request_method=POST
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> Content-Length: 38
->
>> {"name":"Lorem","description":"Ipsum"}
<- HTTP/1.1 302 Found
<- X-Frame-Options: SAMEORIGIN
<- X-Xss-Protection: 1; mode=block
<- X-Content-Type-Options: nosniff
<- Location: http://192.168.0.168:3000/api/styles/19
<- Content-Type: text/html; charset=utf-8
<- Cache-Control: no-cache
<- X-Request-Id: b5bbef5f-a627-424d-bbaf-892bf8aac758
<- X-Runtime: 11.910362
<- Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
<- Date: Fri, 06 Nov 2015 15:31:48 GMT
<- Content-Length: 105
<- Connection: Keep-Alive
<-
-> POST /api/styles/19 HTTP/1.1
-> Host: 192.168.0.168:3000
-> User-Agent: libcurl/7.43.0 r-curl/0.9.3 httr/1.0.0
-> Accept-Encoding: gzip, deflate
-> Cookie: request_method=POST
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
->
<- HTTP/1.1 411 Length Required
<- Content-Type: text/html; charset=ISO-8859-1
<- Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
<- Date: Fri, 06 Nov 2015 15:31:48 GMT
<- Content-Length: 307
<- Connection: close
<-
Response [http://192.168.0.168:3000/api/styles/19]
Date: 2015-11-06 15:31
Status: 411
Content-Type: text/html; charset=ISO-8859-1
Size: 307 B
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Length Required</TITLE></HEAD>
<BODY>
<H1>Length Required</H1>
WEBrick::HTTPStatus::LengthRequired
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) at
192.168.0.168:3000

linkedin API person-activities returns 201 but not able to find the updates in web UI

Request:
POST http://api.linkedin.com/v1/people/~/person-activities HTTP/1.1
Accept-Encoding: gzip, deflate
Authorization: OAuth oauth_token="780e395e-995a-41e9-83d6-6bac16046edc", oauth_consumer_key="******", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1421211087", oauth_nonce="-973828846827772736", oauth_signature="*******"
Content-Type: application/xml
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.7.0_65
Host: api.linkedin.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 187
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><activity locale="en_US"><timestamp>1421211086614</timestamp><content-type>linkedin-html</content-type><body>test2</body></activity>
Response:
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
x-li-request-id: OJY853L13Z
Vary: Accept-Encoding
Date: Wed, 14 Jan 2015 04:51:22 GMT
X-Li-Fabric: prod-ltx1
Set-Cookie: lidc="b=TB24:g=27:u=159:i=1421211082:t=1421253804:s=803971352"; Expires=Wed, 14 Jan 2015 16:43:24 GMT; domain=.linkedin.com; Path=/
Connection: keep-alive
X-Li-Pop: prod-nsg7
X-LI-UUID: 9lTE+PInuROg1UwMlCsAAA==
Set-Cookie: lidc="b=TB24:g=27:u=159:i=1421211082:t=1421253804:s=803971352"; Expires=Wed, 14 Jan 2015 16:43:24 GMT; domain=.linkedin.com; Path=/
Content-Length: 0
But when I go to my home page # profile->your network update, I am not able to see my posts.
I waited more than 30 mins.

how to change standard header value in restlets?

I have the following get:
#Get
public String represent(Variant variant) throws ResourceException
{
String text = "returntext";
text+="\r\n";
return text;
}
The response from invoking this service:
CFG - HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Type: text/plain;charset=UTF-8
Date: Mon, 29 Jul 2013 19:59:37 GMT
Server: Restlet-Framework/2.0.9
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Length: 118
Connection: keep-alive
How do I change the connection header value to close ?
I think this maybe a restlet bug.
Whether the server closes the connection or not, depends on whether the client request asks for the connection to close or not.
Here is a sample Server code:
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";
}
}
And here is what i got on linux commmand line (using only telnet):
[Please note that the last line in request-header in each request is followed by 2 newlines] [To avoid any confusion, some of the requests do not contain request-body.]
[root#mylinuxserver]# 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.
[root#mylinuxserver]# 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.
[root#mylinuxserver]# 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.
[root#mylinuxserver]#
In the above examples, several types of HTTP connections are made.
The response to the 1st request:
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
[Note: the line Host: 172.16.101.34:6060 is followed by 2 \r\n: \r\n\r\n]
is:
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
The connection is not closed yet, and we send another request:
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
Connection: Keep-Alive
That gets the response:
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
Still the connection is not closed.
However on the 3rd request:
GET /TestRestlet HTTP/1.1
Host: 172.16.101.34:6060
Connection: close
The connection is closed, because the request contains Connection: close header.
You can see the telnet exits after displaying a message: Connection closed by foreign host.
There are 2 more sample request-response in the above given examples:
1.An HTTP 1.0 request:
GET /TestRestlet HTTP/1.0
With response:
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
And the telnet exits after displaying: Connection closed by foreign host.
2.A request without HTTP version mentioned:
GET /TestRestlet
And response is: (Without headers)
Sample Response Text
And the telnet exits with a message: Connection closed by foreign host.
Conclusion:
Whatever is your client / client-program , make it send an HTTP-1.0 request , or a HTTP-1.1 request with Connection: close header.
In Java, you achieve this by:
import java.net.HttpURLConnection;
import java.net.URL;
.
.
.
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://....").openConnection();
httpURLConnection.setRequestProperty("Connection","close");
// rest of the code here....
Also check if a statement like this:
httpURLConnection.disconnect();
can help you disconnect the connection.

Resources