How to make HTTP POST request with url encoded body in flutter?

前端 未结 8 1524
南笙
南笙 2020-12-01 03:59

I\'m trying to make an post request in flutter with content type as url encoded. When I write body : json.encode(data), it encodes to plain text.

If I

8条回答
  •  无人及你
    2020-12-01 04:06

    I suggest using the Dio library. It supports a lot with working with APIs.

    With newest Dio version. Simply do the following:

    BaseOptions options = new BaseOptions(
    baseUrl: "https://www.xx.com/api",
    connectTimeout: 5000,
    receiveTimeout: 3000,);
    Dio dio = new Dio(options);
    //
    Map params = Map();
    params['username'] = '6388';
    params['password'] = '123456';
    //
    response = await dio.post("/login", data: FormData.fromMap(params));
    

提交回复
热议问题