Reputation: 43
I was writing a laravel project aiming to provide an endpoint for receving data through http GET request. When I serve the project with nginx and php-fpm, my request TCP stream is as follows:
GET /blood-sugar?data=5A25101010215H888003000000069141201120207C8_460040124507576_FFFFFFFFFFFFFFFFFFFFFFFFF HTTP/1.1
Host: bioland.txhpro.com
Connection: keep-alive
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
Postman-Token: 67530707-765a-f185-f3a2-6795a6b27b2b
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
HTTP/1.1 200 OK
Server: nginx/1.12.2
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.1.11
Cache-Control: no-cache, private
Date: Tue, 18 Sep 2018 05:05:53 GMT
1e
+IP2F644C030050541209120D051OK
0
There are extra charactors as '1e' and '0' around my response body, which violates my partner's rules.
When I use 'php artisan serve --host=0.0.0.0' and request again, these charactors are gone.
Can you tell me what these charactors are and how to remove them?
Upvotes: 1
Views: 66
Reputation: 2206
It is chunked Transfer encoding. 1e is the length of data here. Either your receiving partner needs to decode that (there may be more chunks following, which means the partner needs to request again and again). Or, you disable chunked encoding on your serving side.
Upvotes: 0
Reputation: 781741
Those are part of the "chunked" transfer encoding. Every chunk begins with a hexadecimal number containing the number of bytes in that chunk, a newline, the specified number of bytes of data, and another newline. The end of data is indicated by a chunk size of 0
.
1e
is hex for 30. The next line contains 30 bytes of data.
The next line begins with 0
, indicating that it's the end of data.
If your partner can't process this, there's a problem with their code. RFC 7230 says:
A recipient MUST be able to parse and decode the chunked transfer coding.
You can disable chunked encoding in NGINX with the
chunked_transfer_encoding off;
directive in the configuration file. See the documentation.
Upvotes: 2