简体   繁体   English

WordPress上有关json-api插件内容的奇怪文本

[英]Wordpress strange text over the content of json-api plugin

I use WordPress 4.1.1. 我使用WordPress 4.1.1。 I tried to install the JSON API plugin. 我尝试安装JSON API插件。

Strange letters are displayed above the JSON content. JSON内容上方显示奇怪的字母。 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? 这些字母出现在这些数字下,那么WordPress系统中的问题是吗?

Please help me to understand and to remove them, because I can't parse my JSON. 请帮助我理解并删除它们,因为我无法解析JSON。

在此处输入图片说明

On localhost it works fine with the same properties and data... 在本地主机上,使用相同的属性和数据可以正常工作...

The letter are: 7b00c, 78709, 6eb3d... and they change with updates.. 这封信是:7b00c,78709、6eb3d ...,它们随着更新而改变。

The strange characters is probably a chunk-size . 奇怪的字符可能是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). 当服务器端进程通过HTTP服务器发送响应时,数据通常会先存储在缓冲区中,然后再传输给客户端(浏览器)。 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. 如果整个响应及时放入缓冲区,服务器将在Content-Length:标头中声明大小,然后将响应原样发送给客户端。

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. 这由Transfer-Encoding: chunked块头指示。 Each chunk is preceeded by its length in hexadecimal (followed by a CRLF -pair). 每个块都以其长度(以十六进制表示)开头(后跟一个CRLF对)。 The end of the response is indicated by a 0 chunk-size. 响应的结尾由0块大小指示。 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. 如果您自己解析HTTP响应,则需要考虑各种复杂性。 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. 您需要检查Transfer-Encoding: chunked块头,然后通过解析和剥离chunk-size部分来组合响应。

It's much easier to use a library such as cURL which will handle all the details for you. 使用诸如cURL之类的库要容易得多,它将为您处理所有详细信息。

One hack to avoid chunks is to send the response using HTTP/1.0 rather than HTTP/1.1 . 避免使用块的一种方法是使用HTTP / 1.0而不是HTTP / 1.1发送响应。 In HTTP/1.0, the length is indicated either by the Content-Length: header, or by closing the connection. 在HTTP / 1.0中,长度由Content-Length:标头或通过关闭连接指示。

Syntax 句法

This is the syntax for chunked bodies specified in RFC 7230 - "Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing" ( ABNF notation): 这是RFC 7230-“超文本传输​​协议(HTTP / 1.1):消息语法和路由”ABNF表示法)中指定的分块主体的语法:

\n4.1. 4.1。 Chunked Transfer Coding 分块传输编码\n\n     chunked-body = *chunk 块状体= *块状\n                      last-chunk 最后一块\n                      trailer-part 拖车零件\n                      CRLF CRLF\n\n     chunk = chunk-size [ chunk-ext ] CRLF 块=块大小[chunk-ext] CRLF\n                      chunk-data CRLF 块数据CRLF\n     chunk-size = 1*HEXDIG 块大小= 1 * HEXDIG\n     last-chunk = 1*("0") [ chunk-ext ] CRLF last-chunk = 1 *(“ 0”)[chunk-ext] CRLF\n\n     chunk-data = 1*OCTET ; chunk-data = 1 * OCTET; a sequence of chunk-size octets 块大小八位字节的序列\n\n     trailer-part = *( header-field CRLF ) trailer-part = *(头字段CRLF)\n\n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM