使用套接字创建原始HTTP请求 [英] Creating a raw HTTP request with sockets

查看:75
本文介绍了使用套接字创建原始HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够构造一个原始HTTP请求并使用套接字发送它。显然,你希望我使用urllib和urllib2之类的东西,但我不想使用它。

I would like to be able to construct a raw HTTP request and send it with a socket. Obviously, you would like me to use something like urllib and urllib2 but I do not want to use that.

它必须看起来像这样:

import socket

tcpsoc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsoc.bind(('72.14.192.58', 80)) #bind to googles ip
tcpsoc.send('HTTP REQUEST')
response = tcpsoc.recv()

显然你还需要请求页面/文件并获取和发布参数

Obviously you would also have to request the page/file and get and post parameters

推荐答案

您需要知道的大部分内容都在HTTP / 1.1规范中,如果您想要自己编写HTTP实现,那么您应该学习它: http://www.w3.org/Protocols/rfc2616/rfc2616.html

Most of what you need to know is in the HTTP/1.1 spec, which you should definitely study if you want to roll your own HTTP implementation: http://www.w3.org/Protocols/rfc2616/rfc2616.html

这篇关于使用套接字创建原始HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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