require_once("curl.func.php");
$method = "POST";
$url = "http://open.liupai.net/isbns";
$headers = NULL;
$params = array(
"appkey" => "yourappsecret",
"sub" => "参数1"
);
$result = api_curl($method, $url, $headers, $params);
if ($result) {
$body = json_decode($result["body"], TRUE);
$status_code = $body["status"];
if ($status_code == "200") {
var_dump($body["result"]);
}else
var_dump($body);
}else
echo "发送请求失败";
/**
* 主函数
* @param args
*/
public static void main(String args[])
{
//请求地址设置
String url = "http://open.liupai.net/isbns";
//请求方法设置
String requestMethod = "POST";
//请求头部设置
Map<String, String> headers = new HashMap<String, String>();
//请求参数设置
Map<String, String> params = new HashMap<String, String>();
params.put("appkey", "yourappsecret");
params.put("sub", "参数1");
String result = proxyToDesURL(requestMethod, url, headers, params);
if (result != null) {
JSONObject jsonObject = JSONObject.parseObject(result);
String status_code = jsonObject.getString("status");
if (status_code.equals("200")) {
System.out.println("请求成功:" + jsonObject.getString("result"));
} else {
System.out.println("请求失败:" + jsonObject.getString("msg"));
}
} else {
System.out.println("发送请求异常");
}
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 测试环境: python2.7
# 安装requests依赖 => pip install requests/ easy_install requests
import requests
import json
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
def api_send_request(method, url, params=None, headers=None):
'''
转发请求到目的主机
@param method str 请求方法
@param url str 请求地址
@param params dict 请求参数
@param headers dict 请求头
'''
method = str.upper(method)
if method == "POST":
return requests.post(url=url, data=params, headers=headers)
elif method == "GET":
return requests.get(url=url, params=params, headers=headers)
else:
return None
method = "POST"
url = "http://open.liupai.net/isbns"
headers = None
params = {
"appkey" : "yourappsecret",
"sub" : "参数1"
}
result = api_send_request(method=method, url=url, params=params, headers=headers)
if result:
body = result.result
response = json.loads(body)
status_code = response["status"]
if (status_code == "200"):
print("请求成功:%s" % (body,))
else:
print(
{
"status": 200,
"msg": "查询成功",
"result": {
"levelNum": "9.2",
"subtitle": "",
"author": "[哥伦比亚] 加西亚·马尔克斯",
"pubdate": "2011-6",
"origin_title": "Cien años de soledad",
"binding": "精装",
"translator": "范晔",
"pages": "360",
"images_medium": "http://open.6api.net/lpic/s6384944.jpg",
"images_large": "http://open.6api.net/mpic/s6384944.jpg",
"publisher": "南海出版公司",
"isbn10": "7544253996",
"isbn13": "9787544253994",
"title": "百年孤独",
"summary": "《百年孤独》是魔幻现实主义文学的代表作,描写了布恩迪亚家族七代人的传奇故事,以及加勒比海沿岸小镇马孔多的百年兴衰,反映了拉丁美洲一个世纪以来风云变幻的历史。作品融入神话传说、民间故事、宗教典故等神秘因素,巧妙地糅合了现实与虚幻,展现出一个瑰丽的想象世界,成为20世纪最重要的经典文学巨著之一。1982年加西亚•马尔克斯获得诺贝尔文学奖,奠定世界级文学大师的地位,很大程度上乃是凭借《百年孤独》的巨大影响。",
"price": "39.50"
}
}