我该如何在Flutter http post requset中发送类似“ this”的请求正文?

时间:2019-01-06 06:31:10

标签: dart flutter

我正在尝试制作一个应用程序,在该应用程序中,我基本上是将该应用程序设置为httpClient,该客户端仅从该应用程序中获取输入,然后将其发送到网站,然后它解析该网页并从中显示特定文本(kinda表)它。

因此,我使用的是http.post(),通过浏览器正常用户交互的http请求是这样的:

POST /example/Directory/xxx HTTP/1.1
Host: www.example.com
Connection: keep-alive
Content-Length: 15
Cache-Control: max-age=0
Origin: http://www.example.com
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Save-Data: on
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://example.com
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
X-Hola-Unblocker-Bext: reqid 14107: before request, send headers
X-Hola-Request-Id: 14107

请求主体为:

date=07-01-2019

我尝试在http.post()的'body:'参数中发送“ date = 07-01-2019”,我也尝试在body中像使用{'date':'07-01-2019'} :论点。

我什至尝试将{'date':'07-01-2019'}存储在变量中,然后在其上使用json.encode(),但是没有运气。

timeTableFetch() async{
  String url = "http://example.com";
  var response = await http.post(Uri.encodeFull(url), headers: {"Content-Type": "application/x-www-form-urlencoded", 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}, body: "date=07-01-2019");
  var document = parse(response.body);
  var timeTable = document.getElementsByTagName("gradienttable");//this is what i want

}

所以我希望得到将要进一步处理的timeTable变量,但我无法获得尝试打印页面HTML的HTML,该HTML显示响应即将到来,但发送的日期无效。 / p>

我已经阅读了DartLang上的文档,他们使用了这样的正文

var url = "http://example.com/whatsit/create";
http.post(url, body: {"name": "doodle", "color": "blue"});

但是在我的代码中仍然无法执行

更新代码:

timeTableFetch() async{
  String url = "http://example.com";
  var response = await http.post(Uri.encodeFull(url), headers: {"Content-Type": "application/x-www-form-urlencoded", 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}, body: {'date': '07-01-2019'});
  var document = parse(response.body);
  var timeTable = document.getElementsByTagName("gradienttable");//this is what i want

}

0 个答案:

没有答案