【发布时间】:2018-08-21 15:25:32
【问题描述】:
let headers = new Headers({
'Content-Type' : 'application/json'
});
let options = new RequestOptions({ headers: headers });
this.http.post('https://cors-anywhere.herokuapp.com/'+url, body, options)
.subscribe(data => {
let response = JSON.parse(data['_body']);
if (response.MessageCode == 'SUCCESS') {
this.loginMessage = 'success';
this.navCtrl.push(HomePage, response);
}
else {
this.loginMessage = 'failure';
}
}, error => {
console.log(error);
});
我遇到了 CORS 问题。所以,我在 URL 之前使用它来使它工作。
下面是config.xml
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.16" />
<plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
<plugin name="cordova-plugin-device" spec="^2.0.1" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-advanced-http" spec="^1.11.0" />
请求标头-
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Connection: keep-alive
Host: 64.77.72.122
Origin: http://localhost:8100
响应标头-
Connection: close
Content-Length: 1245
Content-Type: text/html
Date: Thu, 15 Mar 2018 15:37:44 GMT
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
我已经尝试了其他类似问题中提到的所有选项,例如下面提到的问题。
有人可以解决这个问题吗? TIA。
【问题讨论】:
-
您能否包含您看到的一整套请求和响应标头,用于预检 OPTIONS 请求(如果有)以及您尝试发出的 GET/POST 请求.
-
已编辑。请看一看。
-
没关系。修复。它与服务器端和正文参数有关。感谢您的宝贵时间!
标签: typescript http ionic-framework cors cordova-plugins