如何编写连接到给定Web服务器的C程序? [英] How Can I Write A C Program That Connects To A Given Web-Server?

查看:43
本文介绍了如何编写连接到给定Web服务器的C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Write a C program that connects to a given Webserver, and downloads a given Webpage hosted
by the server. For simplicity, assume the Webpage is a static, pure HTML page.

推荐答案

它不难



a)设置一个套接字 - 你需要主机,页面&port(也许这些可以作为参数传递) - 大约11行代码

b)使用来自(a)的套接字发出连接 - 1行代码

c) 你可能需要写一个GET [path] HTTP / 1.0和一个HOST语句到套接字

d)读取返回的数据从套接字 - 2行代码可以覆盖(d&e)

e)将结果从(d)写入文件或stdout

f)关闭并整理 - 2-3行代码



没有评论,大约20-30行代码



我们打算为你写作业/作业
Its not hard

a) set up a socket - for which you'll need host, page & port (maybe these can be passed as parameters) - about 11 lines of code
b) issue a connect using the socket from (a) - 1 line of code
c) [edit - whoops, its a web server you're speaking to] you may need to write a GET [path] HTTP/1.0 and a HOST statement to the socket
d) read the data that comes back from the socket - 2 lines of code can cover (d & e)
e) either write the results from (d) to a file or stdout
f) close and tidy up - 2-3 lines of code

Without comments, its about 20-30 lines of code

we arnt going to write your homework/assignment for you


这篇关于如何编写连接到给定Web服务器的C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆