jyo*_*ran 5 android cordova ionic-framework cordova-plugins ionic2
我只是想在我的IONIC 2项目中进行http post调用.当我运行离子服务时它工作正常.但是当我运行离子运行anroid以在我的设备上运行它时它给了我403(禁止)响应.
这是我的PaymentService.ts,其中已经进行了http调用
import {Http, Headers, RequestOptions} from '@angular/http';
import 'rxjs/add/operator/map';
import { Injectable } from '@angular/core';
@Injectable()
export class PaymentService {
static get parameters() {
return [[Http]];
}
constructor(private http:Http) {}
postToPaymentApi(data) {
let headers: Headers = new Headers()
headers.set('Content-type', 'application/x-www-form-urlencoded')
let options = new RequestOptions({headers: headers})
var response = this.http.post("http://test/url",data,options).map(res => res.json());
return response;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为了克服这个问题,我尝试了几件事,比如
<meta http-equiv="Content-Security-Policy" content="default-src *; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"><access origin>*<allow-navigation>,<allow-intent>标记具有指定属性.但就我而言,没有上述解决方案可行.
当我从我的Android设备点击后调用时,我收到以下错误响应:
{"_body":"",
"status":403,
"ok":false,
"statusText":"Forbidden",
"headers":{"Date":["Wed","30 Nov 2016 09:28:53 GMT"],
"Content-Length":["0"]},
"type":2,
"url":"http://test/url"}
Run Code Online (Sandbox Code Playgroud)
我有以下离子信息:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.12
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v7.2.0
Xcode version: Not installed
Run Code Online (Sandbox Code Playgroud)
有解决方案的人吗?
提前致谢.
你能试试这个例子吗?您确定发送了正确的标头吗
postToPaymentApi(data) {
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
return new Promise(resolve => {
this.http.post('http://test/url',data, {headers: headers })
.subscribe(respond => {
console.log(respond);
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |