http链接url地址后进行POST、PUT、GET、DEL操作
2016-10-18 06:40
741 查看
现在做的项目,需要经常链接到url地址上查看数据,因此写了个通用的CRUD操作的脚本,不同的操作在method的地方填写。如POST、PUT、DELETE、GET等操作
import httplib import json import re class HttpRequest(object): def http_request(self, data, requrl, method): re_str = '.*://(.*)/api' re_pat = re.compile(re_str) search_ret = re_pat.search(requrl) ipaddress_port = search_ret.group() ipaddress_port_info = ipaddress_port[0] ipaddress = ipaddress_port_info.split(":")[0] port = int(ipaddress_port_info.split(":")[1]) post_data = json.dumps(data) headerdata = {"Content-type":"application/json"} try: conn = httplib.HTTPConnection(ipaddress, port) conn.request(method=method, url=requrl, body=post_data, headers=headerdata) response = conn.getresponse() return response.read() except Exception, e: print 'error %s' % str(e.args) finally: if conn: conn.close()
相关文章推荐
- URL描述资源,HTTP方法(get,put,delete,post)描述操作
- "Android下使用HttpUrlConntion"进行最简单的get,post请求(包括创建服务器)
- python_HTTP(实现GET、PUT、POST、DELETE操作)
- pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
- asp.net 自定义 Http Post,Get,WebClient ,TcpClient 请求url地址
- Android实例demo15之HttpUrlConnect的get、post操作、asynchttp
- REST = HTTP动词(GET POST PUT DELETE)操作 + 服务器暴露资源URI,最后返回状态码(充分利用HTTP自身的特征,而不仅仅是把HTTP当作传输协议。Rest协议是面向资源的,SOAP是面向服务的),表现形式可以是JSON XML BIN,举例很清楚
- REST应该放弃使用http头GET、POST、PUT和DELETE来表达操作
- 复习URLHttpConnection方式GET,POST方式链接网络解析uri
- PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)
- url 的httppost 和http get ,put,delect
- pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
- 复习URLHttpConnection方式GET,POST方式链接网络解析uri
- url 的httppost 和http get ,put,delect
- java使用HttpURLConnection和HttpClient分别模拟get和post请求以及操作cookies
- Android HttpURLConnection(Get,Post方式)进行网络通信 获取数据和网络图片
- Analyze URL Redirection with HTTP GET&POST
- Http Get Post put delete
- HTTP Status 405 - HTTP method GET(POST) is not supported by this URL
- C# URL中的http链接进行分析,将相对路径转换为绝对路径 源代码