#!/usr/bin/env python
# Filename: post.py
import sys
def send(host,port,request):
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.sendall("GET / HTTP/1.1
Content-Length:%d
%s
"%(len(request),request))
while 1:
buf = s.recv(1024*8)
if not len(buf):
break;
sys.stdout.write(buf)
sys.stdout.write("
")
#parse argv
n = len(sys.argv)
if n != 4:
print "Usage: ./post.py IP_ADDRESS PORT post.xml"
sys.exit()
else:
send(sys.argv[1],int(sys.argv[2]),open(sys.argv[3]).read())
[yangtze@contex201 ~]$ cat POST.xml
hello world!
[yangtze@contex201 ~]$ ./post.py 192.168.101.11 6040 POST.xml
HTTP/1.1 200 OK
Content-Length: 13
hello world!