dongmi5020 2017-07-10 14:01
浏览 43

不同的标头休息

I'm creating a little mobile application in ionic with rest API.

I have a problem with request headers and I don't know how to set headers on server side or in application.

I have following code:

export function registration(data) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization', 'Bearer ' + token);

    let options = new RequestOptions({headers: headers})

    return this.http.post(API_URL, JSON.stringify(data), options)
                .toPromise()
                .then(response => validateResponseCode([202], response))
                .then(response => response.json());
}

screen all headers (local/prod)
screen all headers (local/prod)

When is API_URL located on localhost is everything ok and headers are set correctly (left side of image).

but when I change API_URL to production server headers are wrong and request failed. (right side of image)

I can edit mobile application or server (PHP), but I don't know what set.

I tried to set headers:

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, 
X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");

But it doesn't work.

Thank you for help


ionic -v 3.4.0
php -v 7.0.15
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿