4

I am having problem in sending Authorization header with POST request to api written in java, i am attaching my code with response and request headers.

$.ajax({
    url: 'http://' + URLDomain + ':9090/path/to/api',
    type : 'POST',
    beforeSend: function (xhr) {             
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xhr.setRequestHeader("Authorization", encryptedText);
        },
    data: 'contentKey='+dataToSend,
     success: function(resp){
         console.log(resp);
     },
     error: function (err){
         console.log(err);
     }
});

Request Header: Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:accept, access-control-allow-headers, access-control-allow-origin, authorization, content-type Access-Control-Request-Method:POST Cache-Control:no-cache Connection:keep-alive Host:xxx.xxx.x.xx:9090 Origin:http://xxx.xxx.x.xxx Pragma:no-cache Referer:http://xxx.xxx.x.xxx/Project/path/Web/ User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Response Header: Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, authorization Access-Control-Allow-Methods:POST, GET, HEAD, OPTIONS Access-Control-Allow-Origin:http://xxx.xxx.x.xxx Content-Length:0 Date:Wed, 27 Jul 2016 12:42:09 GMT Set-Cookie:JSESSIONID=xk1ehwk88fn1tk8k6f81sojx;Path=/;HttpOnly

i have followed following links : How to make GET CORS request with authorization header and How to add CORS support on the server side in Java with Jersey But problem is still not solved.

Community
  • 1
  • 1
Gaurav Chauriya
  • 304
  • 2
  • 12

0 Answers0