Python Socket programming: Post sentence - Info not reaching to web server? -
so got web-server , can display info next code
#!/usr/bin/env python import socket import sys host = 'www.inf.utfsm.cl' = '/~mvaras/tarea1.php' ua = 'tarea1' port = 80 try: sock = socket.socket(socket.af_inet, socket.sock_stream) except socket.error, msg: sys.stderr.write("[error] %s\n" % msg[1]) sys.exit(1) try: sock.connect((host, port)) except socket.error, msg: sys.stderr.write("[error] %s\n" % msg[1]) sys.exit(2) sock.send("get %s http/1.1\r\nhost: %s\r\n\r\nuser-agent: %s\r\n\r\n" % (get, host, ua)) sock.send("post alexis ahumada 17536441-2http/1.1\r\n\r\nuser-agent: tarea1\r\n\r\n") data = sock.recv(1024) string = "" while len(data): string = string + data data = sock.recv(1024) sock.close() print string sys.exit(0)
but thing info send (alexis ahumada 17536441-2) never writes on server log (www.inf.utfsm.cl/~mvaras/tarea1.log) i'd want know i'm doing wrong. appreciated i've looked everywhere :(
change
tcp_ip = ('http://www.inf.utfsm.cl/~mvaras/tarea1.php')
to
tcp_ip = 'www.inf.utfsm.cl'
and need send http request "~mvaras/tarea1.php"
the trouble trying communicate in http protocol on tcp connection - http higher level protocol.
instead of using socket
need use requests library this.
Comments
Post a Comment