想用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
|
1
2
3
|
.
/configure
make
make
install
|
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
|
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
//
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);
|