导航:首页 > 编程系统 > linuxchttp库

linuxchttp库

发布时间:2023-04-26 10:06:08

① 如何用c语言实现http服务器

//服务端简易代码如下:
#include<stdio.h>
#include<stdlib.h>

#include<err.h>
#include<event.h>
#include<evhttp.h>

voidhttp_handle(structevhttp_request*req,void*arg);/*HTTPRequestHandle*/

intmain(){
structevhttp*httpd;
event_init();
httpd=evhttp_start("0.0.0.0",2345);
if(httpd==NULL){
fprintf(stderr,"Error:Unabletolistenon%s:%d ");
exit(1);
}
evhttp_set_timeout(httpd,2000);
evhttp_set_gencb(httpd,http_handle,NULL);
event_dispatch();
evhttp_free(httpd);

return0;
}

voidhttp_handle(structevhttp_request*req,void*arg){
structevbuffer*buf;
buf=evbuffer_new();

/*Responsetheclient*/
evhttp_send_reply(req,HTTP_OK,"OK",buf);

//evbuffer_add_printf(buf,"%s","HTTPSQS_AUTH_FAILED");

/*Releasethememory*/
evbuffer_free(buf);
fprintf(stderr,"Send ");
}

编译:编译时把libevent的类库中的.so文件和.h文件连接进来。

linux下的静态库和动态库

linux下的静态库和动态库1.制作自己的动态库和静态库linux下动态库以.so结尾,静态库以.a结尾,它们都以lib开头,比如一个库名为net,那么它的全名应该是libnet.so或者libnet.a。我们有两个文件,hello.c和test.c,下面是两个文件的内容//hello.c
www.shiwu.com
#include
<stdio.h>void
my_lib_func(){printf(Library
routine
called/r/n);}//test.c#include
<stdio.h>
www.shiwu.com
int
main(){my_lib_func();return
1;}test.c调用了hello.c的方法,我们把hello.c封装成库文件。无论是静态库还是动态库,都是由.o文件组成,我们先把gcc
-c
hello.c生成.o文件制作静态库ar
crv
libmyhello.a
hello.o,ar是生成静态库的命令,libmyhello.a是我的静态库名。下一步就是在我的程序中使用静态库
可以看到已经有了Library
routine
called的结果,说明调用成功了。下面我们删除libmyhello.a,看看程序是否还是运行正常
我们发现程序依然运行正常,说明静态库已经连接进入我们的程序中制作动态库
www.shiwu.com
我们看见动态库libmyhello.so已经生成,下面继续使用
找不到库文件,这个时候我们把so文件拷贝到/usr/lib下面
运行成功2.动态库和静态库同时存在的调用规则我们可以发现,不论是动态库还是静态库,程序编译连接的时候都是加的参数-l,那么当他们同时存在的时候,程序会选择动态库还是静态库呢。我们做个尝试。
我们同时存在libmyhello.a和libmyhello.so,我们发现运行的时候,出现找不到动态库的错误,由此,我们可以得出结论,同时存在动态库和静态库的时候,gcc会优先选择动态库作者
梨树阳光

③ linux c++中要如何调用一个http接口

可以使用libcurl 库

https://curl.haxx.se/libcurl/

#include<stdio.h>
#include<curl/curl.h>

intmain(void)
{
CURL*curl;
CURLcoderes;

curl=curl_easy_init();
if(curl){
curl_easy_setopt(curl,CURLOPT_URL,"curl.haxx.se");
res=curl_easy_perform(curl);

/*alwayscleanup*/
curl_easy_cleanup(curl);
}
return0;
}

更多的例子在这里https://curl.haxx.se/libcurl/c/example.html

④ C/C++ 怎么获取网页内容

解析不到的,网页内容是在服务器已经生成后再传送到客户端,浏览器只是将接收到的内容显示出来而已

⑤ 在LINUX下如何利用C语言实现HTTP的get和post方法

下载wget的源码看看就知道了

⑥ 大神们,常用的linux c/c++ http开源库有哪些,给个推荐吧

客户端库有libcurl
服务端库有基于libevent的libevhtp

⑦ linux C 下想把pcap文件中的http数据包里的gzip压缩的内容解出来!有没有人做过!或是有什么办法吗

兄弟,找出解决办法,告诉我一声,我最近也在找相关的东西,头都大了。。。。

⑧ 设计一个linux c语言,Http协议的服务器,用socket收发消息,简单点,求代码and注释。

OK
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <string.h>

int main(int argc,char *argv[])
{
int sockfd,new_socket;
int sock_value;
char buf[] = "hello! China!I Love You\n";

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 2){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[1])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&server_,SIZE);

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = INADDR_ANY;

if(bind(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("bind");
exit(1);
}

if(listen(sockfd, 12) == -1){
perror("listen");
exit(1);
}

printf("Waiting ... ...\n");

while(1){
if((new_socket = accept(sockfd,(struct sockaddr *)(&client_),&SIZE)) == -1){
perror("accept");
exit(1);
}

printf("The client IP is %s\n",inet_ntoa(client_.sin_addr));
printf("The socket is %d\n",ntohs(client_.sin_port));

if(write(new_socket,buf,strlen(buf)) == -1){
perror("write");
exit(1);
}

int my;
char mybuf[1024];

if((my = read(new_socket, mybuf,1024)) == -1){
perror("read");
exit(1);
}

mybuf[my] = '\0';
printf("#++++#++++#:%s\n",mybuf);

close(new_socket);

}

close(sockfd);

return 0;
}

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
int sockfd;
int sock_value;
char buf[1024];
char mybuf[] = "Linux\n";
int read_count;

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 3){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[2])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&client_,SIZE);
bzero(&server_,SIZE);

client_.sin_family = PF_INET;
client_.sin_port = htons(52252);
client_.sin_addr.s_addr = INADDR_ANY;

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = inet_addr(argv[1]);

if(connect(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("connect");
exit(1);
}

if((read_count = read(sockfd,buf,1024)) == -1){
perror("read");
exit(1);
}

buf[read_count] = '\0';
printf("#----#----#:%s\n",buf);

if(write(sockfd, mybuf,6) == -1){
perror("write");
exit(1);
}

close(sockfd);

exit(0);

return 0;
}

⑨ 有没有用C或c++写的web服务器

cpp-net lib cpp-netlib: The C++ Network Library,号称是要进入标准的,但是感觉还不stable;
facebook做了一个HTTP库 facebook/proxygen · GitHub,只对Linux系统比较版友好;
另外还有权一个叫pion的HTTP库 splunk/pion · GitHub

C/C++好的网络库有很多,像asio, libevent, libuv等的性能都是极好的,可以在这个基础上加上HTTP协议解析,比如用joyent的http_parser,然后就是处理HTTP协议本身了,但这个时候问题就来了,是支持到1.1还是2.0?要不要支持SPDY、WebSocket?

没有GC的语言处理字符串是很虐心的,如果一定要强求用C++,那我只能安慰题主:node也是C++写的,你就当node的框架是C++ Web服务器咯~

更好的选择是用nginx,靠谱,实用。

⑩ linux下C语言怎么读取http文件内容

http是协议
不是文件
你这个说法就有问题了。
如果你想用C读网页 可以考虑使用socket 不过还是有些麻烦的。

阅读全文

与linuxchttp库相关的资料

热点内容
如何打开crv文件 浏览:41
md文件夹在win7不能打开 浏览:668
颂拓手表运动数据如何导入微信 浏览:654
什么网站信访最有效 浏览:396
魅蓝e2升级安卓70 浏览:438
黄石响应式网站建设多少钱 浏览:410
怎么把excel工作簿放到一个文件夹 浏览:949
wifi网络延时大怎么处理 浏览:345
云办公的原理是把传统文件放哪里 浏览:113
不属于群防群治队伍数据项有哪些 浏览:404
java树向上找 浏览:241
数据库查询票价 浏览:503
word黑色下划线怎么去掉 浏览:879
学习编程怎么学比较好 浏览:351
有什么好看的地图网站 浏览:593
oppo如何设置app黑名单 浏览:71
移动数据用了多少在哪里显示 浏览:549
excel表改变文件名颜色的方法 浏览:966
linuxshell二进制文件 浏览:36
什么是网络道德问题产生的 浏览:836

友情链接