1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
13 from oslo_serialization import jsonutils
16 logger = logging.getLogger(__name__)
19 class HttpClient(object):
21 def post(self, url, data):
22 data = jsonutils.dump_as_bytes(data)
23 headers = {'Content-Type': 'application/json'}
25 response = requests.post(url, data=data, headers=headers)
26 result = response.json()
27 logger.debug('The result is: %s', result)
30 except Exception as e:
31 logger.debug('Failed: %s', e)
35 response = requests.get(url)
36 return response.json()