gpt4 book ai didi

http - 状态错误 : Cannot set the body fields of a Request with content-type "application/json"

转载 作者:行者123 更新时间:2023-12-03 02:38:52 26 4
gpt4 key购买 nike

Map<String,String> headers = {'Content-Type':'application/json','authorization':'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='};

var response = await post(Urls.getToken,
headers: headers,
body: {"grant_type":"password","username":"******","password":"*****","scope":"offline_access"},
);


当我执行此操作时,我无法接收数据并且抛出的错误是

错误状态:无法设置内容类型为“application/json”的请求的正文字段

最佳答案

您需要将 body 包裹在 jsonEncode 中.

import 'package:http/http.dart' as http;
import 'dart:convert';

Map<String,String> headers = {'Content-Type':'application/json','authorization':'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='};
final msg = jsonEncode({"grant_type":"password","username":"******","password":"*****","scope":"offline_access"});

var response = await post(Urls.getToken,
headers: headers,
body: msg,
);

关于http - 状态错误 : Cannot set the body fields of a Request with content-type "application/json",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54849725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com