last day (14 days later) » 

3:06 AM
0
A: How to send a POST request with the Javascript Soup library?

Joeytje50How about this? msg = Soup.Message.new('POST', self.url) //... Going by this page, combined with the code you posted, I'd say you would send your request parameters via the request body like this: msg = Soup.Message.new('POST', self.url) msg.body('?try=this&perhaps=it&works'); Otherwise, ju...

 
I should have seen that answer coming. :) The question is: Where to put the data?
 
@lyle could you link me to the library's page please?
 
Good thinking. :) Never occured to me they should have their own documentation somewhere: wiki.gnome.org/Projects/libsoup
It's a C library, so they have C examples. Still need to figure out how the JS bindings look like.
 
@lyle I've posted what I'd say it might be. I'm not at all sure about it though.
 
Nope, both don't work. There's no function called .body(), and adding the parameters to the url makes them GET parameters.
 
3:06 AM
@lyle how about this? By the way, do you have any live examples where I can test for myself?
 
"Soup.Message.set_request (msg, 'try=this')" seems to be going somewhere, but it says the method expects 4 arguments.
 
Hi there
@lyle Are you there?
 
@Joeytje50 My first time chatting here. Still trying to figure out how it works. :)
 
@lyle That's okay
 
Ah, think I got it. :)
 
3:08 AM
@lyle Could you try putting Soup.Message.set_request in your console, and see what it returns?
 
There's a console?
 
@lyle What browser do you use?
 
I'm using Anjuta as IDE. I'm writing a native Gnome application, not a web app.
 
@lyle I see. Okay, are you using either one of the links listed on wiki.gnome.org/JavaScript ?
 
Yes, gjs.
 
3:15 AM
@lyle Hang on there, I'm trying to find the source code for the Soup.Message.set_request function
They've really got some terrible documentation here..
 
The documentation leaves some room for improvement, indeed. :)
 
Could you try something like this:
Soup.Message.set_request(msg, 'application/x-www-form-urlencoded', Soup.Memory.COPY, 'try=this&I_hope=it&does=work');
@lyle That is based on the syntax on developer.gnome.org/gnome-devel-demos/stable/… and on the set_request syntax suggested by stackoverflow.com/questions/10178750/http-post-with-libsoup
 
TypeError: Soup.Memory is undefined
 
Soup.Message.set_request(msg, 'application/x-www-form-urlencoded', Soup.MEMORY_COPY, 'try=this&I_hope=it&does=work');
@lyle perhaps that works then?
 
nope, that one doesn't work either.
Funny error message, though: TypeError: Soup.Message.set_request is not a function
Mixed with: Error: Too few arguments to method Soup.set_request expected 4 got 2
 
3:30 AM
Interesting. Could you try something like this:

Soup.set_request(msg, 'application/x-www-form-urlencoded', Soup.MEMORY_COPY, 'try=this&I_hope=it&does=work');
 
I'm quite sure it's supposed to be msg.set_request (... rather than Soup.Message.set_request (msg, ...)
 
@lyle Did it work when you tried that?
 
almost...
It accepted Soup.Memory_COPY, but asked for one more argument.
 
@lyle Soup.MEMORY_COPY or Soup.Memory_COPY?
 
msg.set_request ('application/x-www-forum-urlencoded', Soup.Memory_COPY, 'try=this');
leads to
Error: Too few arguments to method Soup.set_request expected 4 got 3
Both Soup.MEMORY_COPY and Soup.Memory_COPY give the same result.
 
3:34 AM
@lyle ah I see.
@lyle Could you try this then:
 
Looks like I can put anything there. I tried Soup.MENARY_COPIES and it didn't complain either.
Ah, right, that'll be undefined then.
 
var POSTparams = 'try=this';
msg.set_request ('application/x-www-form-urlencoded', Soup.Memory_COPY, POSTparams, POSTparams.length);
@lyle mind the application/x-www-form-urlencoded though, it's -form-, not -forum-
 
Error: Expected type enum for Argument 'req_use' but got type 'undefined'
form, right. :D That would have given me sleepless nights later. :)
 
@lyle Try this then...
var POSTparams = 'try=this';
msg.set_request ('application/x-www-form-urlencoded', Soup.MEMORT_COPY, POSTparams, POSTparams.length);
@lyle at this point it's starting to look a bit like a guessing game, but I hope it won't take too long
 
undefined
 
3:40 AM
oh typo there
var POSTparams = 'try=this';
msg.set_request ('application/x-www-form-urlencoded', Soup.MEMORY_COPY, POSTparams, POSTparams.length);
 
I'm trying to just put in numbers. It works in the sense that the code executes, but the variables aren't included in the POST request.
'2' worked :)
 
@lyle So your full request looks like this then right?
var POSTparams = 'try=this';
msg.set_request ('application/x-www-form-urlencoded', 2, POSTparams, POSTparams.length);
 
yep :)
 
@lyle Nice, I'll update my answer, then you can mark it as completed
 
Thank you so much! :)
 
3:50 AM
@lyle I've updated my answer, so you can mark your answer as answered now
Good luck with the rest of the code by the way, sounds like this is going to be a challenge, especially without the proper documentation
@lyle Are you still there?
 
4:21 AM
Sorry, didn't want to be rude. Answer accepted. :)
 

last day (14 days later) »