Mag*_*s W 5 rest http dart flutter
我试图使用Dio 插件调用 REST 服务,但不断收到HTTP 400响应代码。我认为通过将内容类型和响应类型选项设置为 JSON,我做的一切都是正确的:
Response response = await Dio().get(
'https://api.example.com/v1/products/$productId',
queryParameters: {},
options: Options(
contentType: ContentType.json,
responseType: ResponseType.json,
headers: {'Authorization': 'Bearer $MY_API_KEY'}
),
);
Run Code Online (Sandbox Code Playgroud)
然而,事实证明我Content-Type还需要添加一个标头:
headers: {'Authorization': 'Bearer $MY_API_KEY'}, 'Content-Type': 'application/json' };
Run Code Online (Sandbox Code Playgroud)
所以现在我很困惑 - 这个contentType选项到底有什么作用?我认为这类似于Content-Type手动设置标题?
| 归档时间: |
|
| 查看次数: |
13065 次 |
| 最近记录: |