Trouble using HTTP POST with libsoup

北城余情 提交于 2019-12-11 18:23:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!