发表于: 2020-07-10 23:45:15
1 1821
今天完成的事情
1. 完成了七牛云图片的上传
生成 token 下发到用户访问的网页,用户直接提交图片到七牛云,不用经过我的服务器转发。
收获
1. from 表单提交的格式
之前一直不知道 from 表单提交的数据是个什么格式,所以我做起来总觉得不知道怎么下手。
Query String Parameters
当发起一次GET请求时,参数会以url string的形式进行传递。即?
后的字符串则为其请求参数,并以&
作为分隔符。
如下http请求报文头:
// General
Request URL: http://foo.com?x=1&y=2
Request Method: GET
// Query String Parameters
x=1&y=2
Form Data
当发起一次POST请求时,若未指定content-type,则默认content-type为application/x-www-form-urlencoded。即参数会以Form Data的形式进行传递,不会显式出现在请求url中。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: application/x-www-form-urlencoded; charset=UTF-8
// Form Data
x=1&y=2
Request Payload
当发起一次POST请求时,若content-type为application/json,则参数会以Request Payload的形式进行传递(显然的,数据格式为JSON),不会显式出现在请求url中。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: application/json; charset=UTF-8
// Request Payload
x=1&y=2
如果希望通过Form Data的方式来传递数据,则可以通过原生方法formData()来进行数据组装,且content-type需要设置为multipart/form-data。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: multipart/form-data; charset=UTF-8
// Request Payload
------WebKitFormBoundaryAIpmgzV8Ohi99ImM
Content-Disposition: form-data; name="x"
1
------WebKitFormBoundaryAIpmgzV8Ohi99ImM
Content-Disposition: form-data; name="y"
2
------WebKitFormBoundaryAIpmgzV8Ohi99ImM--
其中,WebKitFormBoundaryAIpmgzV8Ohi99ImM
为浏览器随机生成的boundary
,作为分隔参数,作用等同于&
。
作者:JSoon
链接:https://www.jianshu.com/p/c81ec1a547ad
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
遇到的问题
1. 防盗链与跨域
还是没搞清楚这个跨域到底限制了个什么东西,对于浏览器我真的一无所知。
今天向一个前端师兄请教了一下,我还是一脸懵逼。
明天的计划
1. 使用腾讯云 OSS
实现两个对象存储的切换
2. 做一下邮件、验证码防护
评论