使用libsoup的HTTP POST [英] HTTP POST with libsoup
本文介绍了使用libsoup的HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用libsoup执行一个简单的POST请求。我想要发送数据的网站的API只需要一个名为内容的字段。用curl我这样做:
I'd like to execute a simple POST request using libsoup. The api of the website i'd like to send data to requires only one field named 'content'. With curl i do this:
curl -si -F 'content=mycontent' http://mywebsite.org/api
如何使用libsoup做同样的事?
How can I do the same with libsoup?
推荐答案
Google可能比我更适合你。这里是一个与libsoup客户端基础的链接。 http://developer.gnome.org/libsoup/stable/libsoup-client -howto.html
Google probably does this better for you than me. Here is a link with the libsoup client basics. http://developer.gnome.org/libsoup/stable/libsoup-client-howto.html
从那里你应该尝试类似
guint status;
SoupMessage *msg;
const char * mycontent; //alloc and fill this with your data
msg = soup_message_new ("POST", "http://example.com/form.cgi");
soup_message_set_request (msg, "whatever content type here",
SOUP_MEMORY_COPY, mycontent, strlen (mycontent));
status = soup_session_send_message (session, msg);
//error handling etc
这篇关于使用libsoup的HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文