javascript - 在 JS 上复制 python 请求的错误请求错误
问题描述
我正在开发一个后端在 python 中的应用程序,因为我正在使用烧瓶和招摇。
从 python 我提出请求为:
headers = {'content-type': 'application/json'}
data = {}
url = 'http://SERVERIP:5100/api/generatate_response'
resp = requests.post(url,data=json.dumps(data), headers=headers )
r = (json.loads(resp.text))
并得到回应:
{'status': 'OK'}
现在我正在尝试使用 fetch 从 JS 做同样的事情:
let data = {
name: 'John',
surname: 'Smith'
};
function sentData () {
fetch("http://SERVERIP:5100/api/generatate_response", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}
)
.then( function(res) {
return res.json()
})
.then(function(data) {
console.log(data)
} )
}
但我收到以下错误:
VM220:2 Mixed Content: The page at 'https://www.google.com/search?sxsrf=ALeKk03JfQaAaOO7vKNvyv6lmE8E2OB7qg%3A1589647482208&ei=ehjAXoylDLvW5OUP-rC2oA0&q=err_ssl_protocol_error+stack+overflow&oq=ERR_SSL_PROTOCOL_ERROR+stack&gs_lcp=CgZwc3ktYWIQAxgAMgUIABDLATIGCAAQFhAeOgQIABBHOgQIABBDOgIIADoHCAAQFBCHAlDzNFinO2CERWgAcAF4AIABa4gBpwOSAQM1LjGYAQCgAQGqAQdnd3Mtd2l6&sclient=psy-ab' was loaded over HTTPS, but requested an insecure resource 'http://52.170.1.84:5100/api/generatate_response'. This request has been blocked; the content must be served over HTTPS.
sentData @ VM220:2
(anonymous) @ VM242:1
我正在从 chrome 控制台执行此操作:
然后我尝试了同样的方法,只是将 url 从 http 更改为 https:
并得到了另一个错误:
VM258:2 POST https://SERVERIP:5100/api/generatate_response net::ERR_SSL_PROTOCOL_ERROR
sentData @ VM258:2
(anonymous) @ VM263:1
从服务器端:
xxx - - [16/May/2020 16:57:12] code 400, message Bad request version ('"\x00"ÊÊ\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00')
xxx - - [16/May/2020 16:57:12] " üGWÁ`'§=ñu,åZúCÊïĽLEÑÐ_}ßë %eFª zûjOqÐéÝ'émºN@%RÄ" "ÊÊÀ+À/À,À0̨̩ÀÀ / 5 " HTTPStatus.BAD_REQUEST -
服务端调用的方法是:
def generatate_response(documents):
"""
"""
print ("request received")
result = {"status":"OK"}
return result