HTTP basic access authentication

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

HTTP basic access authentication

Postby vasil » Thu Dec 01, 2011 7:44 pm

How to authenticate using plugins.http.createNewHttpClient()?

What is the purpose of the parameters defined in executeRequest(username, password)?
The documentation says nothing.

The following code dose not work:
Code: Select all
    var httpClient = plugins.http.createNewHttpClient();
    var url = 'http://localhost:8080/service'; // requires authentication
    var getRequest = httpClient.createGetRequest(url);
    var username = 'foo';
    var password = 'bar';
    var response = getRequest.executeRequest(username, password);
    application.output(response.getStatusCode());

Result is:
403.0


The following code works as I expect:
Code: Select all
    var httpClient = plugins.http.createNewHttpClient();
    var url = 'http://localhost:8080/service'; //requires authentication
    var getRequest = httpClient.createGetRequest(url);
    var username = 'foo';
    var password = 'bar';
    getRequest.addHeader('Authorization', 'Basic ' + Base64.encode(username + ':' + password));
    var response = getRequest.executeRequest();
    application.output(response.getStatusCode());

result is:
200.0
vasil
 
Posts: 18
Joined: Thu Oct 20, 2011 1:17 pm

Re: HTTP basic access authentication

Postby rgansevles » Fri Dec 02, 2011 3:58 pm

vasil,

I tried the same (first sample) code and it worked as expected: 200

Note that http 403 is not Unauthorized (which is 401) but Forbidden, so I guess the user has logged in but is not allowed.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: HTTP basic access authentication

Postby vasil » Mon Dec 05, 2011 7:43 pm

Rob, you are right. It works.

I have to provide more information.
I am trying to interact with RESTful API. The server requires preemptive authentication.
I think that plugins.http does not provide out of the box preemptive authentication.
vasil
 
Posts: 18
Joined: Thu Oct 20, 2011 1:17 pm

Re: HTTP basic access authentication

Postby rgansevles » Tue Dec 06, 2011 9:53 am

Vasil,

If you file a feature request in our support system we will have a look if that is feasible for the plugin.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL


Return to How To

Who is online

Users browsing this forum: No registered users and 4 guests