2

I'm trying to write a Gnome program in Javascript. HTTP requests are done with a library called Soup, and GET requests start with something like:

msg = Soup.Message.new('GET', self.url) ...

Examples for GET requests are all over the net, but how to do a POST request?

lyle
  • 757
  • 1
  • 7
  • 18

1 Answers1

2

Based on our chat conversation, this code will work:

msg = Soup.Message.new('POST', self.url);
var POSTparams = 'try=this';
msg.set_request ('application/x-www-form-urlencoded', 2, POSTparams, POSTparams.length);

The syntax seems to be:

msg.set_request('MIME type', (2), 'params=here', 'params=here'.length);

This answer was also based on the following:

Community
  • 1
  • 1
Joeytje50
  • 18,636
  • 15
  • 63
  • 95
  • 1
    I should have seen that answer coming. :) The question is: Where to put the data? – lyle Jan 30 '14 at 02:15
  • @lyle could you link me to the library's page please? – Joeytje50 Jan 30 '14 at 02:19
  • Good thinking. :) Never occured to me they should have their own documentation somewhere: https://wiki.gnome.org/Projects/libsoup – lyle Jan 30 '14 at 02:25
  • It's a C library, so they have C examples. Still need to figure out how the JS bindings look like. – lyle Jan 30 '14 at 02:32
  • @lyle I've posted what I'd say it might be. I'm not at all sure about it though. – Joeytje50 Jan 30 '14 at 02:37
  • Nope, both don't work. There's no function called .body(), and adding the parameters to the url makes them GET parameters. – lyle Jan 30 '14 at 02:45
  • @lyle how about this? By the way, do you have any live examples where I can test for myself? – Joeytje50 Jan 30 '14 at 02:50
  • "Soup.Message.set_request (msg, 'try=this')" seems to be going somewhere, but it says the method expects 4 arguments. – lyle Jan 30 '14 at 03:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46393/discussion-between-joeytje50-and-lyle) – Joeytje50 Jan 30 '14 at 03:06
  • Too many arguments to method Soup.Message.set_request: expected 3, got 4 – eexpress Jan 11 '22 at 15:51