python get、post请求接口

GET:

import urllib,urllib2

import json

def get(url):
    h={"appkey":"  ","Content-Type":"application/json"}
    req=urllib2.Request(url = url,headers=h)
    res=urllib2.urlopen(req)
    ress=res.read()

POST:

import urllib,urllib2

import json

def post(url):

     h={"appkey":"  ","Content-Type":"application/json"}

    data={'',''}

    data=json.dumps(data)

    req = urllib2.Request(url = url,data = data,headers=h)
    res_data = urllib2.urlopen(req)
    res = res_data.read()


猜你喜欢

转载自blog.csdn.net/qq_40771567/article/details/80354764