9.用C语言在Linux中使用http协议浏览网页
[toc]
用C语言在Linux中使用http协议浏览网页
1.用C语言在Linux中使用http协议浏览静态网页
LinServer.c
这个服务器程序将能够处理GET请求,并返回一个简单的HTML页面。
1 | //LinServer.c |
LinClient.c
这个客户端程序将请求服务器的静态网页,并打印出服务器的响应。
1 | //LinClient.c |
运行结果
运行
LinServer运行
LinClient或浏览器中访问http://127.0.0.1:8080/First.html运行成功
2.修改程序,让程序可以解析同当前录中的First.html文件
First.html
在当前目录下创建一个名为First.html的文件,并添加一些HTML内容
1 | <html> |
LinServer.c
这个服务器程序将能够处理GET请求,并返回当前目录下的First.html文件内容。
1 | //LinServer.c |
LinClient.c
这个客户端程序将请求服务器的First.html文件,并打印出服务器的响应。
1 | //LinClient.c |
运行结果
在当前目录创建
First.html运行
LinServer运行
LinClient或者浏览器中访问http://127.0.0.1:8080/First.html运行成功
3.修改服务端程序,让程序可以访问多个html文件
LinSever.c
设置当前目录为基本路径,设置绝对路径通过相对路径访问First.html
1 |
|
运行结果
- 在当前目录创建
First.html - 运行
LinServer - 运行
LinClient或者浏览器中访问http://127.0.0.1:8080/First.html - 运行成功
4. 修改程序,让程序可以解析css
1. 修改First.html
将First.html文件保存在”/home/kali/cc++/http/First/First.html”中
1 |
|
2.修改LinServer.c
1 | //LinServer.c |
3. 运行结果
- 运行LinServer
- 在浏览器中访问
http://127.0.0.1:8080/First/First.html - 运行成功,显示绿字体
5. 修改程序,让程序可以解析javascript
1. 修改First.html
1 |
|
2.创建example.js
在D:\First文件夹中创建example.js
1 |
|
3. 修改LinServer.c
1 | // LinServer.c |
4. 运行结果
运行
LinServer浏览器中访问
http://127.0.0.1:8080/First/First.html运行成功
6.设置utf8编码,并让客户端能去除html标签只显示文本内容
LinClient.c
1 | //LinClient.c |
LinServer.c
1 | //LinServer.c |
运行结果
运行
LinServer运行
LinClient后输入html文件路径/First/First.html运行成功
7. 用C语言在Linux中使用http协议浏览网页http://info.cern.ch/
1 |
|
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
