python - urllib2问题求助

查看:83
本文介绍了python - urllib2问题求助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

python里的urllib2.request怎么判断是get请求还是post请求啊 就是我自己传一个url进去 我怎么知道这次是进行post还是get请求呢?

解决方案

根据python官方文档的描述:

class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])

This class is an abstraction of a URL request.

url should be a string containing a valid URL.

data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format.

如果data参数值为None或者没有传data参数,那么就是get请求,否则就是post请求

这篇关于python - urllib2问题求助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆