Add: Set the encoding method
SetRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded; charset = gb2312 ")
Syntax
Oxmlhttprequest. setRequestHeader (bstrheader, bstrvalue );
Parameters
Bstrheader string, header name.
Bstrvalue string, value.
Still not quite clear
1. xmlobject. setRequestHeader "Content-Type", "application/X-WWW-form-urlencoded"
What does Content-Type mean, application/X-WWW-form-urlencoded?
2. What are the meanings of setRequestHeader?
SetRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");SetRequestHeader ("Content-Length", paramssend. Length ); SetRequestHeader ("connection", "close "); |
Answer:
In HTTP, when a client obtains a webpage like a server, it must send an HTTP header file,
Tell the Server Client what information to download and related parameters, such:
GET/BB. asp? WWW = 1234 HTTP/1.1
Accept :*/*
Accept-language: ZH-CN
UA-CPU: x86
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
HOST: www.e4j.cn: 89
Connection: keep-alive
COOKIE: % C3 % F7 % CC % EC = % B0 % CB; aspsessionidasdbsdrr = bledbibbcgkbjakjcfejkgii
XMLHTTP is used to obtain file data on the website through the HTTP protocol, so it also needs to send an HTTP header to the server.
However, some parameters in XMLHTTP may not be described in the HTTP header by default. This is used when we need to modify or add these parameters.
SetRequestHeader method.
For example, if the content of the above HTTP header file is the default situation of XMLHTTP submission, this will happen after the setRequestHeader method is used, as shown in:
Xmlobject. setRequestHeader "Content-Type", "application/X-WWW-form-urlencoded"
SetRequestHeader "connection", "close"
In this case, the HTTP header information should be like this:
GET/BB. asp? WWW = 1234 HTTP/1.1
Accept :*/*
Accept-language: ZH-CN
UA-CPU: x86
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
Content-Type: Application/X-WWW-form-urlencoded
HOST: www.e4j.cn: 89
Connection: Close
COOKIE: % C3 % F7 % CC % EC = % B0 % CB; aspsessionidasdbsdrr = bledbibbcgkbjakjcfejkgii
The setRequestHeader method is only an interface method provided by XMLHTTP to add or modify HTTP headers,
The value in it is the meaning of the HTTP protocol. Of course, you can also send your own stuff in. Even if IIS cannot identify your information, no error will be reported.
For example, setRequestHeader "myname", "supermanking"
Although IIS does not report errors, this information can also be useful. You can read the HTTP header information in the ASP program to check whether there is any
Myname: supermanking information, which can be processed based on your needs. Also, Content-Type: application/X-WWW-form-urlencoded indicates that the encoding method for the content submitted by the client to the server text is URL encoding, that is, except for standard characters, each byte is represented by "%" before the double-byte hexadecimal notation.
Of course, there are other encoding methods, such as Content-Type: multipart/form-data.
Content-Length indicates the size of the submitted data bytes.
HTTP has several submission methods, including get and post.
This sign is placed at the beginning of the HTTP header, which is easy to understand.
The get method does not submit content, so Content-Length is invalid in get mode.
The get parameter is transmitted through a virtual address, for example:
GET/BB. asp? WWW = 1234 HTTP/1.1
All the parameters are as many as "www = 1234"
If post is used, there will be some differences. Post places the parameters after HTTP. The above HTTP is used as an example to transmit parameters through post.
Post or BB. asp HTTP/1.1
Accept :*/*
Accept-language: ZH-CN
UA-CPU: x86
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322;. Net CLR 2.0.50727)
Content-Type: Application/X-WWW-form-urlencoded
HOST: www.e4j.cn: 89
Content-Length: 8
Connection: Close
COOKIE: % C3 % F7 % CC % EC = % B0 % CB; aspsessionidasdbsdrr = bledbibbcgkbjakjcfejkgii
WWW = 1, 1234
In this case, the data needs to indicate the size of the byte.
As for connection: close, it is obvious that connection: Close
The client only tells the server who will close the connection when submitting data.