C语言的http库 libghttp
openkk
13年前
<p>libghttp 是一个很好用的 http 库,这个库十分的方便使用,它能够轻松地实现同步和异步的Http请求。</p> <p>示例代码:</p> <p></p> <pre class="brush:cpp; toolbar: true; auto-links: false;">#include <ghttp.h> int main(int argc, char *argv[]) { char *uri = "http://www.oschina.net/"; ghttp_request *request = NULL; ghttp_status status; char *buf; int bytes_read; request = ghttp_request_new(); if(ghttp_set_uri(request, uri) == -1) exit(-1); if(ghttp_set_type(request, ghttp_type_get) == -1) exit(-1); ghttp_prepare(request); status = ghttp_process(request); if(status == ghttp_error) exit(-1); /* OK, done */ printf("Status code -> %d\n", ghttp_status_code(request)); buf = ghttp_get_body(loader->request); bytes_read = ghttp_get_body_len(loader->request); return 0; }</pre> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1325148114046" target="_blank">http://www.open-open.com/lib/view/home/1325148114046</a></p> <p></p>