Wordpress strange text over the content of json-ap

2019-07-08 08:03发布

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.

enter image description here

On localhost it works fine with the same properties and data...

The letter are: 7b00c, 78709, 6eb3d... and they change with updates..

1条回答
ら.Afraid
2楼-- · 2019-07-08 08:38

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 a CRLF-pair). The end of the response is indicated by a 0 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 the chunk-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):

4.1.  Chunked Transfer Coding

     chunked-body   = *chunk
                      last-chunk
                      trailer-part
                      CRLF

     chunk          = chunk-size [ chunk-ext ] CRLF
                      chunk-data CRLF
     chunk-size     = 1*HEXDIG
     last-chunk     = 1*("0") [ chunk-ext ] CRLF

     chunk-data     = 1*OCTET ; a sequence of chunk-size octets

     trailer-part   = *( header-field CRLF )

查看更多
登录 后发表回答