我试图通过在Android设备(6.0.1)上运行我的应用程序来进行简单的发布请求。AFAIK在执行此操作时没有CORS问题,但是控制台输出以下内容:
(出于某种原因,apiurl替换了实际的url,实际的url是IP地址)
POST file:///android_asset/www/apiurl net::ERR_FILE_NOT_FOUND
我添加了cordova白名单插件并设置了我的内容安全策略:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
这是我的邮寄要求代码:
$scope.powerPrompt = function() {
var pwr = alert("Power On");
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
$http({
method: 'POST',
url: 'apiurl',
data: "data to be sent",
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(response) {
// handle success things
alert("success");
})
.error(function(data, status, headers, config) {
// handle error things
})
如评论中所述,您需要确保为URL加上前缀,http://
否则它将尝试通过来访问文件系统file://
,这就是为什么您收到未找到文件的错误的原因。
确保您以以下格式发出请求:
http://<api url>:<ports if necessaray>/path/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句