我的API调用需要在标头中传递API密钥,但我从API服务收到错误信息{"error":"2424452","message":"Invalid Api Key"}
我知道我的API密钥是有效的,因为我可以在Python中进行相同的API调用,例如:
req = requests.Session()
req.headers.update({'x-api-key': 'my-api-key', 'X-Product': 'my-product-name'})
req.get(url)
但是在JavaScript中,同样的调用会出错。我认为我没有正确设置头信息或其他什么问题吗?
var req = new XMLHttpRequest();
req.onreadystatechange=handleStateChange;
req.open("GET", "url", true);
req.setRequestHeader("Host", "api.domain.com", "x-api-key", "my-api-key", "X-Product", "my-product-name");
req.send();
- 这个
XMLHttpRequest
不是在浏览器中调用,而是在支持XMLHttpRequest
的应用程序中使用。
XMLHttpRequest
不是在浏览器中调用,而是在支持 XMLHttpRequest
的应用程序中使用。