XMLHttpRequest returning 405 on preflight


#1

XMLHttpRequest cannot load http://www.URLHERE.com/iCommerce/users.asmx. Response for preflight has invalid HTTP status code 405

I got above error while use webapp in chrome. Can anyone help me in this?


#2

Normally, it has to do with CORS issue. The preflight request is being fired first to your server and your app is failing the auth.
What is the $http code you are sending to the URL.
try this:
app.config([’$httpProvider’, function ($httpProvider) {
//Reset headers to avoid OPTIONS request
$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
}]);


#3

It is normal to get this issue.
All the times that happened with me the problem was that the server was not set to allow requests from your domain.
To solve this you need to add this header in your server:
"Access-Control-Allow-Origin: http://yourorigindomain.com"
Or simply add the header below that allows requests from all origin domains:
"Access-Control-Allow-Origin: *"


#4

Nothing Works!!! Any other solution?


#5

As I said: this is a configuration of server side not of your ionic app.


#6

It works on Android and iOS. But not in chrome (browsers)


#8

First, can you say which action you are sending to server, meaning GET/POST/PUT/DELETE
Secondly, seeing the web service is a .asmx url , which means the server is in asp.net.

For Browsers, You have to enable CORS in the web.config file.

<httpProtocol>
  <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
       <add name="Access-Control-Allow-Headers" value="Content-Type" />
      <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
 </customHeaders>
</httpProtocol>

#9

On server side where soap services are created or in app config.xml?


#10

The person who created the Web Service will be the best person to do this. Assuming it is in his asp .net code, you have to add it in his web.config file as i showed earlier.

Unfortunately, you being the client, can only ensure your app in browser is called in the same domain as the server as allowed him to.
If you pass the Access Control Allow Origin check and still don’t see your data in the right way, check if you have sent Content Type as ‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’