【发布时间】:2015-07-03 17:29:44
【问题描述】:
我需要将文件上传到服务器,该文件需要在请求标头中发送身份验证代码。所以我需要发送:
POST /upload/file HTTP/1.1
Host: www.example.com
Authorization-code: xxxxx
file data
我通过 requestmaker.com 向服务器发送了一个带有 Authorization-code 标头的 POST 请求,但没有任何文件数据。服务器响应正常。
然后我想通过带有method=POST的HTML表单发送file data和Authorization-code
我对 HTML 没有深入的了解,所以我不知道幕后究竟发生了什么。我想,method=POST 将发送带有请求标头的数据。但是,服务器响应类似于Authorization failed。然后,通过网页上的inspecting element,我看到浏览器在请求期间没有发送表单值。下面是inspect element->network->header的输出
**General**
Remote Address:x.x.x.x
Request URL:www.example.com
Request Method:POST
Status Code:401 OK
**Response Headers**
access-control-allow-credentials:true
access-control-allow-origin:http://mywebsite.com
access-control-expose-headers:Content-Length, Content-Type, Date, Server, Transfer-Encoding, Vary, WWW-Authenticate
alternate-protocol:443:quic,p=1
content-length:238
content-type:application/json; charset=UTF-8
date:Fri, 24 Apr 2015 22:15:37 GMT
server:UploadServer ("Built on Apr 20 2015 22:37:13 (1429594633)")
status:401
vary:X-Origin
vary:Origin
www-authenticate:realm="https://www.example.com"
**Request Headers**
:authority:www.example.com
:method:POST
:path:/upload/drive/v2/files?uploadType=media
:scheme:https
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
accept-encoding:gzip, deflate
accept-language:en-US,en;q=0.8,en-GB;q=0.6
cache-control:max-age=0
content-length:104
content-type:application/x-www-form-urlencoded
dnt:1
origin:http://mywebsite.com
referer:http://mywebsite.com/uoh/xxx.html
user-agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36
x-client-data:CJC2yQEIo7bJAQiptskBCMS2yQEI8IjKAQieksoB
**Query String Parameters**
uploadType:media
**Form Data**
Authorization-code:xxxx
谁能解释一下这种行为?表单中的实际 POST 数据何时发送到服务器?关于如何在请求标头中发送数据的任何建议?
【问题讨论】:
标签: html forms post file-upload http-headers