gpt4 book ai didi

post - 带有空体的 Flutter post 方法

转载 作者:行者123 更新时间:2023-12-05 07:22:23 27 4
gpt4 key购买 nike

我使用请求库发布数据,但在服务器上收到空主体,没有传递任何数据。我在代码中遗漏了什么吗?

Map map = new Map<String, dynamic>();
map[csrfNameKey] = csrfName;
map[csrfValueKey] = csrfValue;
map["username"] = idControler.text;
map["password"] = passControler.text;

dynamic data;
data = await Requests.post(widget.url + "login", body: json.encode(map),json: true,headers:{"ContentType":"application/json",HttpHeaders.contentTypeHeader: 'application/json'} ,bodyEncoding: RequestBodyEncoding.JSON);

最佳答案

试试看,

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

fetchDataByPost() async {

Map<String, dynamic> body = {'id': 222, 'name': 'aam'};

String jsonBody = json.encode(body);
final encoding = Encoding.getByName('utf-8');
final header = {'Content-Type': 'application/json'};

Response response = await post(
widget.url + "login",
headers: header,
body: jsonBody,
encoding: encoding,
);

int statusCode = response.statusCode;
String responseBody = response.body;
}

关于post - 带有空体的 Flutter post 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56536638/

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