http Web服务器请求 - 响应 [英] http web server request-response

查看:90
本文介绍了http Web服务器请求 - 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有这个项目,我必须创建一个与浏览器通信的服务器。我必须在浏览器中写这样的东西:http:// localhost:11880 / path

,服务器上打印的信息将是:



GET /路径HTTP / 1.1

主持人:localhost:11880

用户代理:Mozilla / 5.0(X11; U; Linux i686; en-US; rv:1.9.2.12)

Gecko / 20101027 Ubuntu / 10.04(lucid)Firefox / 3.6。 12

接受:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8

Accept-Language:en- us,en; q = 0.5

接受编码:gzip,deflate

Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7

Keep-Alive:115

连接:keep-alive

Referer:http:// localhost:11880 / path



首先,我不明白'会'会做什么。对于get和post方法,打印的消息将有所不同,但是我无法理解我是否必须在浏览器中写入:'get http:// localhost:11880 / path'或者只是'http:// localhost:11880 / path '和get将通过请求打印到服务器。另外我必须向浏览器发送一个RFC响应,但是有很多情况,我不知道在哪种情况下打印每条消息(404:未找到,501未实现等)以及如何打印它。每一个帮助都会受到赞赏,我很绝望,我已经坚持了大约一天。

Hello guys, i'm having this project where i must create a server that communicates with a browser.I must write something like this in the browser: http://localhost:11880/path
and the message printed in the server will be:

GET /path HTTP/1.1
Host: localhost:11880
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12)
Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost:11880/path

Firstly i haven't understand what 'get' will do. The printed message will be different for get and post method, but i cant understand if i will have to write: 'get http://localhost:11880/path' in the browser or just 'http://localhost:11880/path' and get will be printed to server through the request. Additionaly i have to send back to the browser a RFC response, but there are so many cases and i don't know in which case to print each message(404: not found, 501 Not implemented etc) and how to print it. Every help would be appreciated, i am desperate, i have stuck at this point for about a day.

推荐答案

您提供的输入将由浏览器生成。



http:// localhost:11880 / path



上述行意味着;您的浏览器将通过端口11880与您的服务器连接。因此,您的服务器必须响应端口11880



Web服务器执行四个请求



1.获取

2. POST

3.删除//一般为安全目的而禁用

4. HEADER //如果标题响应服务器回复只有标题没有数据。



作为首发,你只考虑消息200和404。



200 =如果文件可用

404 =如果请求的文件不可用



这里是一个http响应的例子:



The input you have provided will be generated by browser.

http://localhost:11880/path

the above line means; that your browser will connect with your server with port 11880. So, your server will have to response to port 11880

There are four request perform by web server

1. GET
2. POST
3. DELETE //in general disabled for security purpose
4. HEADER //in case of header response server reply with only header no data.

As a starter you think only about message 200 and 404.

200=if the file is available
404=if the requested file is not available

here is an example of http response on a requst:

HTTP/1.1 200 OK
Date: Sun, 22 Dec 2013 23:55:12 GMT
Server: Apache
X-Powered-By: PHP/5.3.27
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/javascript



两个重要的回复是

第1行:表示文件状态:

第11行:这将告诉浏览器有关回复数据的类型。

只需要这两个:


two important response is
line 1: that will say file status:
line 11: that will tell the browser about the type of replied data.
just make this two:

HTTP/1.1 200 OK\r\n
Content-Type: text/javascript\r\n





在这两个新线之后必须添加\\\\ n;另一个新行是在内容类型声明结束时





然后最后打印其余的文件内容。



最后不要惊慌



after these two two new line must have to be added "\r\n"; the other new line is at the end of content-type statement


then finally print rest of the file content.

Finally don't panic


这篇关于http Web服务器请求 - 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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