我想通过Dart发送AJAX请求。我希望该请求的主体进行URL编码,就像表单提交一样。我想设置 mime 类型来表明这一点。我该怎么做?
我尝试在请求上设置mimeType
,但这没有帮助。
这是代码:
HttpRequest.request(url,
mimeType: 'application/x-www-form-urlencoded',
sendData: myUrlEncodedString);
最佳答案
不要使用mimeType
,而要使用requestHeaders
。这是一个例子:
HttpRequest.request(url,
requestHeaders: {'Content-Type': 'application/x-www-form-urlencoded'},
sendData: 'hello=world&welcome=todart');
关于dart - 如何在我的Web应用程序中设置Dart的HttpRequest发出的请求的MIME类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222843/