问题
I am trying to log on to my tt-rss server using libsoup. Since version 1.5.3 it only supports HTTP POST to receive data. Basically I only need to do something like this with libsoup:
curl -d '{"op":"login","user":"you","password":"xxx"}' http://example.dom/tt-rss/api/
But all the code examples written in vala using POST are outdated and don't compile anymore. For example the last one on this page, Transmission RPC Interface: https://wiki.gnome.org/Projects/Vala/JsonSample
Here is my code:
var uri = "http://nas/tt-rss/api/";
var session = new Soup.Session ();
var message = new Soup.Message ("POST", uri);
var login = "{\"op\":\"login\",\"user\":\"USER\",\"password\":\"PASSWORD\"}";
message.set_request("", MemoryUse.COPY, login);
session.send_message (message);
stdout.printf("%s \n", (string) message.response_body.flatten ().data);
I always get the error:
Argument 3: Cannot convert from `string' to `uint8[]'
Thanks for any help in advance
best regards, Jan
回答1:
Soup.Message.set_request takes a byte array, uint8[]
, not a string
, as you have provided. You can convert a string
to an array of bytes using the .data
member:
message.set_request("", MemoryUse.COPY, login.data);
来源:https://stackoverflow.com/questions/25405045/trouble-using-http-post-with-libsoup