Python http post socket

saturn99 / SendPost.py

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

import sys
import socket
s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
ipaddr = socket . gethostbyname ( ‘devwerks.net’ )
s . connect (( ipaddr , 80 ))
data = «username=test&pass=blah \n \n «
header = ( «»»
POST /index.php HTTP/1.1
Host: devwerks.net
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://google.com
Cookie: PHPSESSID=blub
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
«»» )
contentLength = «Content-Length: » + str ( len ( data ) ) + » \n \n «
request = header + contentLength + data
s . send ( request )
response = s . recv ( 4096 )
s . close ()
print request
print response + ‘ \n ‘
sys . exit ( 0 )

Источник

Читайте также:  Тег IMG, атрибут align
Оцените статью