时间:2021-07-01 10:21:17 帮助过:22人阅读
这里将实现的技术代码进行公开。
一、Python以GET请求的方式,请求PHP页面,并获得返回值
1、python代码:
[root@AY python]#cat httpclientget.py #!/usr/bin/env python#coding=utf8import httplibhttpclient=Noneprint 'bb'try: httpclient=httplib.HTTPConnection('www.xxx.org',80) httpclient.request('GET','/CloudBean/capture.php?name=liu&pass=wew') res=httpclient.getresponse() print res.status print res.reason print res.read()except Exception,e: print "heelowr"
[root@AY python]#cat /CloudBean/capture.php
1、Python代码:
[root@AY python]#cat httpclientpost.py #!/usr/bin/env python#coding=utf8import httplib,urllibhttpclient=Nonetry: params = urllib.urlencode({'name': 'tom', 'pass': 22}) print 'aaa' headers = {"X-CPU": "arm/x86" , "X-USER": "234299044218541","X-RESOLUTION": "240x320","X-SYSTEM":"2.3","X-LANG":"en-us","X-SIGN":"a1ae6bee406a6b8aa0862969ba49cc1d", "X-IMSI":"3110012345678912","X-COUNTRY":"in","X-TIME":"1335339139"} httpclient=httplib.HTTPConnection('www.xxx.org',80) httpclient.request('POST','/CloudBean/cappost.php',params,headers) res=httpclient.getresponse() print res.status print res.reason print res.read() print res.getheaders()except Exception,e: print "error"
2、PHP代码: [root@AY python]#cat /CloudBean/cappost.php