Flutter Post请求

时间:2019-08-12 21:29:05

标签: api flutter dart

我需要编写带有标头和json主体的Post请求,如下所示;

标题请求:

Content-Type:application/json

Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9

身体要求:

{
  "Data": {
    "Permissions": [
      "ReadAccountsDetail",
      "ReadProducts",
      "ReadStandingOrdersDetail",
      "ReadTransactionsCredits",
      "ReadTransactionsDebits",
      "ReadTransactionsDetail",
      "ReadPAN"
    ],
    "ExpirationDateTime": "2019-06-29T00:00:00+00:00",
    "TransactionFromDateTime": "2019-05-03T00:00:00+00:00",
    "TransactionToDateTime": "2019-12-03T00:00:00+00:00"
  },
  "Risk": {}
}

1 个答案:

答案 0 :(得分:0)

正如塞尔吉奥·伯纳尔(Sergio Bernal)所指出的,您应该在自己的pubspec.yaml中添加<button t-if="request.httprequest.url == '/shop'">Filters OFF</button> <!--Since current_URL would be something like "/shop/category/laptops?filter=5-44" if there were any filters applied --> <button t-else="">Filters ON</button>

http

然后按如下所示导入它:

dependencies:
    ...
    http: any

将允许您使用以下方法:

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

这是您的示例:

http.post(dynamic url, {Map<String, String> headers, dynamic body, Encoding encoding})