-
-
Save likewhoa/8295077 to your computer and use it in GitHub Desktop.
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
# -*- coding:utf8 -*- | |
import urllib | |
import curl | |
import pycurl | |
import StringIO | |
def initCurl(): | |
c=pycurl.Curl() | |
c.setopt(pycurl.FOLLOWLOCATION,0) | |
c.setopt(pycurl.CONNECTTIMEOUT, 10) | |
c.setopt(pycurl.MAXREDIRS,1) | |
c.setopt(pycurl.NOSIGNAL, 1) | |
return c | |
def PostData(curl,url,data): | |
try: | |
head = ['Accept:*/*', | |
'Accept-Charset: utf-8;q=0.7,*;q=0.3', | |
'Accept-Encoding: gzip,deflate', | |
'Accept-Language:zh-CN,zh;q=0.8', | |
'Content-Type: application/x-www-form-urlencoded', | |
'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0'] | |
buf = StringIO.StringIO() | |
curl.setopt(pycurl.WRITEFUNCTION, buf.write) | |
curl.setopt(pycurl.POSTFIELDS,data) | |
curl.setopt(pycurl.URL, url) | |
curl.setopt(pycurl.HTTPHEADER,head) | |
curl.perform() | |
the_page = buf.getvalue() | |
#print the_page | |
buf.close() | |
return the_page | |
except pycurl.error,e: | |
return 'wrong %s'%e | |
data="php" | |
host="http://localhost/post.php" | |
c = initCurl() | |
data=urllib.urlencode({'1':PostData}) | |
html=PostData(c,host,data) | |
print html | |
# my post.php | |
<?php | |
if ($_POST["1"]){echo "ok";} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment