-
v3接口中人脸识别api文档中提示
请求体格式化:Content-Type为application/json,通过json格式化请求体。
在使用json格式请求体时会发送预检请求option,由于我使用的是axios时,设置header 的Content-Type不起作用option请求无法设置,接口直接报错,无请求参数,debug里显示如下Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response
解决方法:
Content-Type: application/x-www-form-urlencoded,不会发起预检请求// 方法1 axios.post(url,JSON.stringify(data)) // 方法2 axios.post(url,data,{ headers:{ 'Content-Type': 'application/json' } }) // 方法3 axios.post(url,Qs.stringify(data))
-
文字识别(OCR)中
文档提示使用
Content-Type: application/x-www-form-urlencoded,这时只能使用方法3;方法1和方法2不能使用
Json.stringify和Qs.stringify有区别Qs.stringify(a) // 'name=hehe&age=10' JSON.stringify(a) // '{"name":"hehe","age":10}'
Qs.stringify是将对象 序列化成URL的形式
JSON.stringify是将对象转化为字符串
方法1和方法2发送的请求参数
正确的应该为
接口会报取不到值