简体   繁体   中英

Vala - How to create a HTTP request with Soup?

I'm a bit lost with vala docs. Im trying to do a POST request to my AJAX service with soap lib, but no luck. Can anyone tell me what i'm doing wrong?

string url = "http://myservice/ajax.php";          

// create an HTTP session
var session = new Soup.Session ();
var message = new Soup.Message ("POST", url);

//Setting params and request
var params = "action=call&method=get_monuments";    
Soup.MemoryUse buffer = Soup.MemoryUse.STATIC;  

//(Error here - Line 73)
message.set_request ("application/x-www-form-urlencoded", buffer, params, params.length);

// send the HTTP request and wait for response
session.send_message (message);
stdout.write(message.response_body.data);

Compiler drops following error:

/home/ibsenleo/valaprojects/test/main.vala(73,73): Error: Argument 3: Cannot convert from `string' to `uint8[]'

I'm sure is something about request parameters and the data type, but i couldn't find some useful examples.

Soup.Message.set_request 's third argument is a uint8[] , not a string , and there is no fourth argument. You probably want something like

message.set_request ("application/x-www-form-urlencoded", buffer, params.data);

See string.data .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM