1

I'm working on a Gnome-shell extension, and I'm stuck in using Soup to contact a server. Basically, I want to send a POST request which can be performed after authentication. If authenticated, the response if a JSON content, and if not authenticated, the response content is HTML, the welcome page of the site. Here is my code so far:

let session = new Soup.SessionSync();
session.user_agent = Me.metadata.uuid;
let authParams = {'login': 'xxx', 'password': 'xxx'};
let message = Soup.form_request_new_from_hash('POST', authURL, authParams);
session.queue_message(message, Lang.bind(this, function(session, response) {
    global.log('AUTHENTICATE: ' + response.status_code + ' - ' + response.reason_phrase);
    global.log('AUTHENTICATE: ' + response.response_body.data);

    let msg = Soup.form_request_new_from_hash('POST', url, params);
    session.queue_message(msg, Lang.bind(this, function(session, response) {
 global.log(response.status_code + ' - ' + response.reason_phrase);
 global.log(response.response_headers.get_one('content-type'));
    }));
}));

I can see that the authentication request works well, according to the response, but the second requests returns me the HTML content. I checked in SoapUI by sending these 2 requests, and it works well (I get some JSON content) when I set the option "Maintain HTTP Session".

Therefore, I'm thinking that my session doesn't store the authentication when the second request is sent. Do you know what I am missing in here, in order to have the authentication saved in my session?

I alternatively tried to use some tips from the following link, but without success: Consume a webservice with basic authentication using Soup

Thanks in advance for your help.

Community
  • 1
  • 1
bo32
  • 33
  • 3

1 Answers1

0

let session = new Soup.SessionSync();
session.user_agent = Me.metadata.uuid;
let authParams = {'login': 'xxx', 'password': 'xxx'};
let message = Soup.form_request_new_from_hash('POST', authURL, authParams);
session.queue_message(message, Lang.bind(this, function(session, response) {
    global.log('AUTHENTICATE: ' + response.status_code + ' - ' + response.reason_phrase);
    global.log('AUTHENTICATE: ' + response.response_body.data);

    let msg = Soup.form_request_new_from_hash('POST', url, params);
    session.queue_message(msg, Lang.bind(this, function(session, response) {
 global.log(response.status_code + ' - ' + response.reason_phrase);
 global.log(response.response_headers.get_one('content-type'));
    }));
}));