当前位置: 首页 > 工具软件 > libghttp > 使用案例 >

c语言的http库libghttp安装

燕航
2023-12-01

c语言的http库libghttp安装

创建时间:2014-01-10 17:31:40 最后修改:2014-01-10 17:31:40

想用C语言写个采集程序,涉及到http相关的东西,找了找,有现成的libghttp库。
libghttp库的官方网址google一下第一条结果一般就是的:http://lfs.linuxsir.org/htdocs/blfscvs/gnome/libghttp.html

将源码包下载下来,进入例行安装流程:
1、解压

?
1
2
tar -xzvf libghttp-1.0.9. tar .gz
cd libghttp-1.0.9
2、安装
?
1
2
3
. /configure
make
make install
安装过种中小插曲:
在执行./configure命令的时候报错:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
checking host system type ... Invalid configuration `x86_64-unknown-linux-gnu ': machine `x86_64-unknown' not recognized
  
  
checking build system type ... Invalid configuration `x86_64-unknown-linux-gnu ': machine `x86_64-unknown' not recognized
  
  
checking for ranlib... ranlib
checking for ld used by GCC... /usr/bin/ld
checking if the linker ( /usr/bin/ld ) is GNU ld... yes
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
updating cache . /config .cache
ltconfig: you must specify a host type if you use `--no-verify'
Try `ltconfig --help' for more information.
configure: error: libtool configure failed
听说在32位操作系统上一般不会有这样的错误,在64位系统上比较常见,原因是软件自身的config.guess和config.sub文件有问题,从系统中复制这两个文件到软件目录覆盖一下重新./configure就可以了(如果不知道这两个文件在哪里,用find查找一下就OK了):
?
1
2
3
4
5
6
7
8
# 首先查找一下config.guess和config.sub文件的目录
find / -name config.guess
find / -name config.sub
  
  
# 将查找出来的文件随便选择一个覆盖到软件目录
cp /usr/share/automake-1 .11 /config .guess .
cp /usr/share/automake-1 .11 /config .sub .

下面是用libghttp搞了一个测试代码,成功编译和运行,证明libhttp安装成功啦:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<libghttp.h>
#include<sthio.h>
  
  
main()
{
         // This is the http request object
         ghttp_request *request = NULL;
         // Allocate a new empty request object
         request = ghttp_request_new();
         // Set the URI for the request object
         ghttp_set_uri(request, "http://www.phpjiayuan.com/" );
         // Close the connection after you are done .
         ghttp_set_header(request, http_hdr_Connection, "close" );
         // Prepare the connection
         ghttp_prepare(request);
         // Process the request
         ghttp_process(request);
         // Write out the body. Note that the body of the request may not be null terminated so we have to be careful of the length. 
         fwrite(ghttp_get_body(request), ghttp_get_body_len(request), 1, stdout);
         // Destroy the request. This closes any file descriptors that may be open and will free any memory associated with the reque
st. 
         ghttp_request_destroy(request);
 类似资料: