简体   繁体   English

响应头随着 Angular 消失

[英]Response header disappears with Angular

I'm trying to get Chrome Logger working in an Angular app running against a PHP backend, but for some reason the X-ChromeLogger-Data header doesn't seem to be coming through when the API is accessed by the Angular app.我试图让 Chrome Logger 在针对 PHP 后端运行的 Angular 应用程序中工作,但由于某种原因,当 Angular 应用程序访问 API 时, X-ChromeLogger-Data标头似乎没有通过。

If I open the API's access point directly or hit it with a jQuery.get() request everything works fine, even if I make the ajax request from another domain.如果我直接打开 API 的访问点或使用jQuery.get()请求点击它,一切正常,即使我从另一个域发出 ajax 请求。 The API also works correctly otherwise, even when used by the Angular app. API 也可以正常工作,即使在 Angular 应用程序使用时也是如此。 It's just that one header disappears somewhere along the way.只是一个标题在途中的某个地方消失了。 It doesn't even appear in Chrome's console.它甚至没有出现在 Chrome 的控制台中。

What could cause a header to disappear?什么可能导致标题消失?

Here's a request made with jQuery.get()这是使用jQuery.get()发出的请求

Request:
GET /?action=load HTTP/1.1
Host: -
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
Origin: -
X-FirePHP-Version: 0.0.6
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Referer: -
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fi-FI,fi;q=0.8,en-US;q=0.6,en;q=0.4,sv;q=0.2

Response:
HTTP/1.1 200 OK
Date: Sat, 07 Nov 2015 10:41:22 GMT
Server: Apache/2.4.12 (Ubuntu)
X-Powered-By: PHP/5.6.11-1ubuntu3.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, X-ChromeLogger-Data
X-ChromeLogger-Data: eyJ2ZXJzaW9uIjoiNC4wIiwiY29sdW1ucyI6WyJsYWJlbCIsImxvZyIsImJhY2t0cmFjZSIsInR5cGUiXSwicm93cyI6W1siQVBJIiwiQVBJIHJlYWNoZWQiLCJ1bmtub3duIiwid2FybiJdXSwicmVxdWVzdF91cmkiOiJcLz9hY3Rpb249bG9hZCJ9
Content-Length: 15
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

And here's one from the Angular app:这是来自 Angular 应用程序的一个:

Request:
GET /?action=load HTTP/1.1
Host: -
Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: -
X-FirePHP-Version: 0.0.6
User-Agent: Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Referer: -
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fi-FI,fi;q=0.8,en-US;q=0.6,en;q=0.4,sv;q=0.2

Response:
HTTP/1.1 200 OK
Date: Sat, 07 Nov 2015 10:34:33 GMT
Server: Apache/2.4.12 (Ubuntu)
X-Powered-By: PHP/5.6.11-1ubuntu3.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, X-ChromeLogger-Data
Content-Length: 15
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

The Angular code used to make the above request:用于发出上述请求的 Angular 代码:

$http.get( endpoint, { params : { action : 'load' } } ).then(
    function( response ) {
        console.log( response );
    },
    function() {
        console.log( 'fail' );
    }
);

After Dvir's tip to further inspect the differences between the requests (with the aid of Fiddler ) I finally manager to solve the problem.在 Dvir 提示进一步检查请求之间的差异(在Fiddler的帮助下)之后,我终于解决了这个问题。 I was running the Angular app with Chrome's mobile device simulator turned on, and it turns out the Monolog ChromePHPHandler requires for the text "Chrome" to be present in the User-Agent header, which it wasn't when the simulator was turned on.我在 Chrome 的移动设备模拟器打开的情况下运行 Angular 应用程序,结果证明Monolog ChromePHPHandler要求文本“Chrome”出现在 User-Agent 标头中,而在模拟器打开时却没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM