cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
889
Views
0
Helpful
4
Replies

How to implement Basic Credentials when making REST webservice call

yudhitanaka
Level 1
Level 1

Hi,

I want to update one of the call variables in dialog object by making a REST webservice request (PUT), and embedded the Basic Credentials in the webservice request.

Can I get an example how to implement Basic Credentials when making REST webservice call?

Thanks in advance!

Best Regards,

Yudhi

1 Accepted Solution

Accepted Solutions

Hi Yudhi,

Basic authentication is simple with jQuery.  Just add this to your $.ajax request. 

headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},

For example:

$.ajax({
type: 'PUT',
url: 'some-url',
headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
dataType: 'xml',
data: 'some-xml-data',
success: function (){
alert('Success!');
}
});

Keep in mind that if you're using jQuery (or any other AJAX method) to do a REST PUT operation, you have to take CORS into account.  Your $.ajax URL has to be on the same server as the web application you're writing.  Otherwise you'll get an error like this:  XMLHttpRequest cannot load [URL]. No 'Access-Control-Allow-Origin' header is present on the requested resource.

Unfortunately, there's no easy answer to that problem.

Thanks,

Nick

View solution in original post