Setting headers for an HTTP request in Soup 3

Hi! I’ve been experimenting with talking with APIs using GJS and Soup. However, some require that I set headers for my requests. I see no documentation about setting headers on Messages or while calling send_and_read. Here is a portion of my code so far:

const uri = GLib.Uri.build(null, 'https://', null, apiHost, apiPort, `${apiPath}${endpoint}`, params, null);
const message = Soup.Message.new_from_uri('POST', uri);
message.set_request_body_from_bytes('application/json', messageBody);
// Set headers for the message?

const response = await session.send_and_read(message, null);

Thanks in advance!

Hello :waving_hand:

Something like this should work, though I didn’t test it:

message.request_headers.append("Authorization", "Bearer foo");

soup.messageheaders

1 Like

Thank you! :purple_heart:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.