POST工具

#!/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\r\nContent-Length:%d\r\n\r\n%s\r\n"%(len(request),request))
while 1:
buf = s.recv(1024*8)
if not len(buf):
break;
sys.stdout.write(buf)
sys.stdout.write("\r\n")

#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!

posted @ 2013-11-02 01:00  艾丽娅的猫  阅读(536)  评论(0编辑  收藏  举报