Flutter 身体在颤振中未使用map发送

Flutter 身体在颤振中未使用map发送,flutter,dart,Flutter,Dart,服务器的响应显示了这一点 {“error”:1,“data”:{},“message”:“请添加必填字段:email,password”}如果没有“content-length”标题,该服务器似乎无法正确接受请求。这将使您的代码正常工作: HttpClient client = new HttpClient(); client.badCertificateCallback = ((X509Certificate cert, String host, int port) => tru

服务器的响应显示了这一点

{“error”:1,“data”:{},“message”:“请添加必填字段:email,password”}

如果没有“content-length”标题,该服务器似乎无法正确接受请求。这将使您的代码正常工作:

HttpClient client = new HttpClient();
    client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);

    String url ='https://dev.jobma.com:8090/v4/jobseeker/login';
    Map map = {
      "email":"hope@yopmail.com",
      "password":"123456"
    };
    print(map);
    HttpClientRequest request = await client.postUrl(Uri.parse(url));
    request.headers.set('content-type', 'application/json');
    request.add(utf8.encode(json.encode(map)));
    HttpClientResponse response = await request.close();
    String reply = await response.transform(utf8.decoder).join();
    print(reply);
HttpClient=newhttpclient();
client.badCertificateCallback=
((X509证书证书证书,字符串主机,int端口)=>true);
字符串url='0https://dev.jobma.com:8090/v4/jobseeker/login';
地图={
“电子邮件”:hope@yopmail.com",
“密码”:“123456”
};
印刷(地图);
//在这里创造身体
List body=utf8.encode(json.encode(map));
HttpClientRequest=wait client.postrl(Uri.parse(url));
request.headers.set('content-type','application/json');
//在此处设置内容长度标题
request.headers.set('Content-Length',body.Length.toString());
//将正文添加到请求中
请求.添加(正文);
HttpClientResponse response=等待请求。关闭();
String reply=wait response.transform(utf8.decoder.join();
打印(答复);
如果没有“content-length”标题,该服务器似乎无法正确接受请求。这将使您的代码正常工作:

HttpClient client = new HttpClient();
    client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);

    String url ='https://dev.jobma.com:8090/v4/jobseeker/login';
    Map map = {
      "email":"hope@yopmail.com",
      "password":"123456"
    };
    print(map);
    HttpClientRequest request = await client.postUrl(Uri.parse(url));
    request.headers.set('content-type', 'application/json');
    request.add(utf8.encode(json.encode(map)));
    HttpClientResponse response = await request.close();
    String reply = await response.transform(utf8.decoder).join();
    print(reply);
HttpClient=newhttpclient();
client.badCertificateCallback=
((X509证书证书证书,字符串主机,int端口)=>true);
字符串url='0https://dev.jobma.com:8090/v4/jobseeker/login';
地图={
“电子邮件”:hope@yopmail.com",
“密码”:“123456”
};
印刷(地图);
//在这里创造身体
List body=utf8.encode(json.encode(map));
HttpClientRequest=wait client.postrl(Uri.parse(url));
request.headers.set('content-type','application/json');
//在此处设置内容长度标题
request.headers.set('Content-Length',body.Length.toString());
//将正文添加到请求中
请求.添加(正文);
HttpClientResponse response=等待请求。关闭();
String reply=wait response.transform(utf8.decoder.join();
打印(答复);

如果您可以使用dart pub中提供的软件包,这将非常容易

HttpClient client = new HttpClient();

client.badCertificateCallback =
  ((X509Certificate cert, String host, int port) => true);

String url = 'https://dev.jobma.com:8090/v4/jobseeker/login';
Map map = {
  "email": "hope@yopmail.com",
  "password": "123456"
};
print(map);

// Creating body here
List<int> body = utf8.encode(json.encode(map));

HttpClientRequest request = await client.postUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');

// Setting the content-length header here
request.headers.set('Content-Length', body.length.toString());

// Adding the body to the request
request.add(body);

HttpClientResponse response = await request.close();
String reply = await response.transform(utf8.decoder).join();
print(reply);

若你们能使用dart酒吧提供的软件包,那个就容易多了

HttpClient client = new HttpClient();

client.badCertificateCallback =
  ((X509Certificate cert, String host, int port) => true);

String url = 'https://dev.jobma.com:8090/v4/jobseeker/login';
Map map = {
  "email": "hope@yopmail.com",
  "password": "123456"
};
print(map);

// Creating body here
List<int> body = utf8.encode(json.encode(map));

HttpClientRequest request = await client.postUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');

// Setting the content-length header here
request.headers.set('Content-Length', body.length.toString());

// Adding the body to the request
request.add(body);

HttpClientResponse response = await request.close();
String reply = await response.transform(utf8.decoder).join();
print(reply);

请检查问题指南以提高获得高质量答案的几率:您是否尝试过给出的答案?请检查问题指南以提高获得高质量答案的几率:您是否尝试过给出的答案?他正在呼叫的域需要客户端。badCertificateCallback需要设置,否则,呼叫将失败。您尝试了吗?他正在调用的域需要设置client.badCertificateCallback,否则调用将失败。你试过了吗?