socket connetion to url with port 80

S

Sakcee

Hi

this is really a stupid question, how can i get page rsponse from a
site e.g. google.com port 80
form socket, can i do something

import socket
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
s.connect( ( "www.google.com", 80 ) )
s.send( "Hello" ) # GET??
response = s.recv(8048)
print response

can i do soemthign like that , can i send somehting to google and get
webpage in return, I know that I can use urllib or httplib etc, but can
i do at socket level?

thanks
 
F

Fredrik Lundh

Sakcee said:
this is really a stupid question, how can i get page rsponse from a
site e.g. google.com port 80
form socket, can i do something

import socket
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
s.connect( ( "www.google.com", 80 ) )
s.send( "Hello" ) # GET??
response = s.recv(8048)
print response

can i do soemthign like that , can i send somehting to google and get
webpage in return, I know that I can use urllib or httplib etc, but can
i do at socket level?

of course, but it helps if you use the HTTP protocol to talk to
the server:

http://effbot.org/zone/effnews-1.htm#sending-an-http-request

</F>
 
S

Sakcee

thanks for the help

I got the response using s.send("GET / HTTP/1.0\r\n\r\n"),

but this socket is being blocked by squid server that we have installed
in our socket. do you know how can i configure the squid to stop
blocking the socket

thanks
 
J

John J. Lee

Sakcee said:
I got the response using s.send("GET / HTTP/1.0\r\n\r\n"),

but this socket is being blocked by squid server that we have installed
in our socket.

You don't have squid installed "in your socket". You have it
installed on a computer. Going through squid may indeed be the only
way of getting to the outside world, depending on how squid and your
network are configured.

do you know how can i configure the squid to stop
blocking the socket

If you don't already know the answer to that (or even if you did), I
wonder if you might live to regret delving into all this nonsense,
but, for example:

http://www.ietf.org/rfc/rfc2617.txt


Or look at httplib.py and urllib.py from the standard library.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top