-
Notifications
You must be signed in to change notification settings - Fork 27.5k
$http service doesn't add (X-Requested-With' :'XMLHttpRequest') header to the request #11008
Comments
Hi, |
@m-amr the actual setting of of headers happens here: angular.js/src/ng/httpBackend.js Lines 52 to 56 in c1199fb
I'm not sure what / how did you debug but I don't see AngularJS doing anything special with the Could you please share a plunker that demonstrates the issue? What is the HTTP method you are using? |
@pkozlowski-opensource i was asking should $http service send 'headers': { 'X-Requested-With' :'XMLHttpRequest'} with the request by default ? |
No, it doesn't send |
I know it's a non-standard header, but a ton of frameworks use this header. Look at how rack (which almost every ruby web-server uses) detects whether a request is XHR or not: https://github.com/rack/rack/blob/master/lib/rack/request.rb#L221 |
@mkonecny, I know a ton of frameworks use this header, but #11008 (comment) 😃 |
Here is the discussion that resulted in the removal of this header: #1004 |
@mkonecny hello from Symfony2 :) |
Using this $http service send 'headers': { 'X-Requested-With' :'XMLHttpRequest'} with the request by default |
@k-vladyslav I had the same problem with Symfony and $http in AngularJS. The Adding manually the necessary headers solves the problem. |
In Angular 2, simply adding the X-Requested-With header makes the request "not simple" and triggers the preflight OPTIONS request.... which likely opens up a whole new ball of worms on the backend. sigh My framework is looking for the X-Requested-With header... so I try to provide it... which sends a OPTIONS request.. which my framework doesn't seem to understand |
呃呃 |
Hello everyone, if you have problems with OPTIONS requests then please check relevant docs about Cross Origin Resource Sharing (CORS), for example in MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS. CORS or OPTIONS requests are NOT Angular(JS) features, they are a part of HTTP and must be handled by setting the correct headers on client and server. Many server frameworks support or expect a
For Angular docs, please see https://angular.io. |
I am trying to call an api
On the server side i was checking if the request is XmlHttpRequest by checking
X-Requested-With' header and i found that it return false
after i added this header to the $http as configuration it works
i debugged angular.js source code and found that angular is creating xhr by this function
should $http service send 'headers': { 'X-Requested-With' :'XMLHttpRequest'} with the request by default ?
The text was updated successfully, but these errors were encountered: