I use WordPress 4.1.1.
I tried to install the JSON API plugin.
Strange letters are displayed above the JSON content. And they update after refresh of the page.
I tried to bring another letter under the code of plugin. These letters appeared under these figures, so is the problem in the WordPress system?
Please help me to understand and to remove them, because I can’t parse my JSON.
On localhost it works fine with the same properties and data…
The letter are: 7b00c, 78709, 6eb3d… and they change with updates..
The strange characters is probably a
chunk-size
.Content-Length
When a server-side process sends a response through an HTTP server, the data will typically be stored in a buffer before it is transmitted to the client (browser). If the entire response fits in the buffer in a timely manner, the server will declare the size in a
Content-Length:
header, and send the response as-is to the client.Chunked Transfer Coding
If the response does not fit in the buffer, or the server decides to vacate the buffer for other reasons before the full size is known, it will instead send the response in chunks. This is indicated by the
Transfer-Encoding: chunked
header. Each chunk is preceeded by its length in hexadecimal (followed by aCRLF
-pair). The end of the response is indicated by a0
chunk-size. The exact syntax is detailed below.Solution
If you are parsing the HTTP response yourself, there are all sorts of intricacies that you need to consider. Chunked encoding is one of them. You need to check for the
Transfer-Encoding: chunked
header and assemble the response by parsing and stripping out thechunk-size
parts.It’s much easier to use a library such as cURL which will handle all the details for you.
One hack to avoid chunks is to send the response using HTTP/1.0 rather than HTTP/1.1. In HTTP/1.0, the length is indicated either by the
Content-Length:
header, or by closing the connection.Syntax
This is the syntax for chunked bodies specified in RFC 7230 – “Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing” (ABNF notation):