我正在使用react native的Fetch API和typescript.
let responseLogin = await fetch('http://url_example', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: requestBody
});
但我得到了如下错误,其中标题是:
Argument of type '{ method: string; headers: { 'Content-Type': string; }; body: string; }' is not assignable to parameter of type 'RequestInit'.
Types of property 'headers' are incompatible.
Type '{ 'Content-Type': string; }' is not assignable to type 'Headers | string[][]'.
Object literal may only specify known properties, and ''Content-Type'' does not exist in type 'Headers | string[][]'.
我还try 创建自定义标题,但没有成功:
let requestHeaders = new Headers();
requestHeaders.set('Content-Type', 'application/json');
// I have also tried adding this at the end but no luck
// requestHeaders.get('Content-Type');
我怎样才能给它添加标题?因为我找不到任何方法来实现这一点,我不知道问题出在哪里.如果我在《postman 》中测试这些,我会得到200条回复,这里我会得到401条回复.
我使用: