【发布时间】:2020-11-06 16:33:50
【问题描述】:
我已经发出了一个 ajax http post 请求并在 Fiddler 中尝试过,它可以工作,但是当我尝试在 Dart 中运行完全相同的请求时,请求正文没有被传输到服务器。我的 Dart 请求正文有问题吗?
Response response = await client.post(
'https://intranet.tam.ch/krm/timetable/ajax-get-timetable',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'de-ch',
'Accept-Encoding': 'gzip, deflate, br',
'Host': 'intranet.tam.ch',
'Origin': 'https://intranet.tam.ch',
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15',
'Connection': 'keep-alive',
'Referer': 'https://intranet.tam.ch/krm/calendar',
'Content-Length': '83',
'Cookie':
'school=krm; sturmsession=xx; sturmuser=xx; username=xx',
'X-Requested-With': 'XMLHttpRequest'
},
body:
'startDate=1597615200000&endDate=598133600000&studentId%5B%5D=x&holidaysOnly=0');
client.close();
print(response.body);
非常感谢任何答案
【问题讨论】:
-
您的方法的其余部分看起来如何?您是否尝试打印
response.body以查看服务器是否给您某种响应? -
我打印了
response.body,它说POST参数“startDate”丢失了,即使它存在于体内也是如此。 -
尝试从您的标题中删除
'Content-Length': '83',。 (它会由库自动再次添加,但如果您的标题中已经有“Content-Length”,它似乎会产生一些问题)。
标签: http post dart xmlhttprequest httpclient