0

I am writing a pre-request script in postman to execute. The code looks like below

var settings={
"url":environment.url+"/fullendpoint",
"method":"post",
"data":"{'Username':'username','Password':'password'}",
"Content-Type":"application/json",
};

$.ajax(settings).done(function (response){
    console.log(response)
});

Executing above, I am getting error as "Response to preflight request doesn't pass access control check:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405.

Above method is basically to login the user to the application and capture the response cookies and headers so that it can be used for the actual api call.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • If you're calling this on the local server, use a relative URL. If it's a remote call you'll need to return CORS headers in the response. If you don't control the server to add those headers, then you will not be able to make this call using JS. – Rory McCrossan Jun 21 '17 at 10:40
  • Also, unrelated to the problem but much better practice, give the `data` property an object, not a string. This way jQuery will serialise the data for you and escape the values where needed. – Rory McCrossan Jun 21 '17 at 10:41

0 Answers0