简体   繁体   English

xmlhttprequest标头定义的含义

[英]xmlhttprequest meaning of headers definition

I should write a journal when I do changes in my code to make it work, sometimes, in a rush, I just put it to work without knowing exactly why. 当我对代码进行更改以使其工作时,我应该编写一本日志,有时,匆忙,我只是在不确切知道原因的情况下将其投入工作。

I did change a setRequestHeader of a xmlhttprequest from "application/x-www-form-urlencoded; charset=UTF-8" to "application/octet-stream", for some reason, but later, when trying to reuse the code to send some vars by POST to a php, it didn't work. 我确实将xmlhttprequest的setRequestHeader从“application / x-www-form-urlencoded; charset = UTF-8”更改为“application / octet-stream”,出于某种原因,但稍后,当尝试重用代码发送时一些vars通过POST到一个PHP,它没有用。 After a while examining the case, I did change it back and the vars finally reach it's destination! 经过一段时间检查案例,我确实改回来了,vars终于到达了它的目的地!

So what means each one of this headers, how it changes the way data is exchanged? 那么这个标题的每一个是什么意思,它如何改变数据的交换方式?

x-www-form-urlencoded means it escapes some special characters and make the whole datapackage (form) one single string. x-www-form-urlencoded意味着它会转义一些特殊字符并使整个datapackage(form)成为一个字符串。 octet-stream i never seen this format but my raw guess is that its a stream of 8 bit chunks of data. octet-stream我从来没有见过这种格式,但我的原始猜测是它是一个8位数据块的流。

application/x-www-form-urlencoded is the content-type for the standard way of encoding form data (which is also used in query strings). application/x-www-form-urlencoded是表单数据编码的标准方式的内容类型(也用于查询字符串)。

application/octet-stream is the content-type for "some bytes of date, in no particular format" (often it is used for "I don't know what this is" and sometimes for "I don't want the browser to know what this is" when Content-Disposition should be used instead). application/octet-stream是“日期的某些字节,没有特定格式”的内容类型(通常用于“我不知道这是什么”,有时用于“我不希望浏览器知道这是什么“当应该使用Content-Disposition时”。

The header doesn't change how the data is exchanged, it just informs the recipient of what format the data is in. 标题不会改变数据的交换方式,只是告知收件人数据的格式。

If PHP is told the data is in a format that it doesn't know how to parse then it won't parse it and populate $_POST and friends. 如果PHP被告知数据的格式不知道如何解析那么它就不会解析它并填充$_POST和朋友。

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

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