python的request模块基本运用

coding=utf-8

import requests
import json

class foo(object):

def __init__(self):

def get(self):
    r = requests.get(r'http://127.0.0.1:8080/hapi-fhir-jpaserver-example/baseDstu3/QuestionnaireResponse/1103')
    print r.text

def post(self):
    headers = {'Content-type': 'application/json+fhir; charset=utf-8'}
    url=r'http://localhost:8080/hapi-fhir-jpaserver-example/baseDstu3/QuestionnaireResponse';
    data=open(r'1.json').read()
    r = requests.post(url, data, headers)
    print r.text

def put(self):
    headers = {'Content-type': 'application/json+fhir; charset=utf-8'}
    url=r'http://localhost:8080/hapi-fhir-jpaserver-example/baseDstu3/QuestionnaireResponse/802';
    data=open(r'1.json').read()
    r =requests.put(url, data=data, headers=headers)

def delete(self):
    r =requests.delete(r'http://localhost:8080/hapi-fhir-jpaserver-example/baseDstu3/Observation/796')
    print r.text

f=foo()

f.get()

你可能感兴趣的:(python代码实例)