eoLinker-API_Shop_猫咪大全_API接口_Java调用示例代码

合集下载

eoLinker-API_Shop_POI检索_API接口_C#调用示例代码

eoLinker-API_Shop_POI检索_API接口_C#调用示例代码

eoLinker-API Shop POI检索 C#调用示例代码POI检索通过关键词查询在某个地区的POI信息,支持市级、区县级查询:比如在广州查询“银行”,接口将会输出所有银行的地理信息列表。

该产品拥有以下APIs:1.POI搜索2.周边POI搜索3.POI多边形搜索注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=97申请API服务1.POI搜索using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/POI/queryPOI";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("keyWords", ""); //查询关键字(规则:多个关键字用“|”分割若不指定city,并且搜索的为泛词(例如“美食”)的情况下,返回的内容为城市列表以及此城市内有多少结果符合要求。

eoLinker-API_Shop_驾考题库(所有车型)_API接口_Java调用示例代码

eoLinker-API_Shop_驾考题库(所有车型)_API接口_Java调用示例代码

eoLinker-API Shop 驾考题库-新 Java调用示例代码驾考题库-新公安部最新驾照考试题库,分科目一与科目二两种题型;包括小车、货车、客车与摩托车四类车型,涵盖C1、C2、A1、A2、A3、B1、B2、D、E、F等驾照类型。

该产品拥有以下APIs:1.获取题目信息2.获取驾考题库列表3.关键字获取题目注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=187申请API服务1.获取题目信息package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String requestMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("questionID", ""); //题目ID,从“获取驾考题目信息”API 获取String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}2.获取驾考题库列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("page", ""); //页码(默认为1)params.put("pageSize", ""); //每页题目数量(默认为30)params.put("licenseType", ""); //驾照类型,0:小车(C1、C2),1:客车(A1、A3、B1),2:货车(A2、B2),3:摩托车(D、E、F)params.put("subjectType", ""); //科目类型,0:科目一,1:科目四(文明考试)String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}3.关键字获取题目package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("page", ""); //页码(默认为1)params.put("pageSize", ""); //每页题目数量(默认为30)params.put("licenseType", ""); //驾照类型,0:小车(C1、C2),1:客车(A1、A3、B1),2:货车(A2、B2),3:摩托车(D、E、F)params.put("subjectType", ""); //科目类型,0:科目一,1:科目四(文明考试)params.put("keyword", ""); //搜索关键字String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}。

eoLinker-API_Shop_淘宝热词查询_API接口_Python调用示例代码

eoLinker-API_Shop_淘宝热词查询_API接口_Python调用示例代码

eoLinker-API Shop 淘宝热词查询 Python调用示例代码淘宝热词查询根据用户输入的关键词,实时查询该词在全站的搜索排名,协助商家全面掌控搜索关键词近期的市场排名,分布特征等。

该产品拥有以下APIs:1.淘宝热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=212申请API服务1.淘宝热搜查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/shopping/queryTBRelatedHotWords" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #查询关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_手机号归属地查询_API接口_Python调用示例代码

eoLinker-API_Shop_手机号归属地查询_API接口_Python调用示例代码

eoLinker-API Shop 手机号归属地查询 Python调用示例代码手机号归属地查询根据中国大陆手机号获取归属地信息。

该产品拥有以下APIs:1.根据手机号获取归属地信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=72申请API服务1.根据手机号获取归属地信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///communication/phone/getLocationByPhoneNu m"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"phoneNum":"" #目标手机号或手机号前7位}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_股票行情数据_API接口_Python调用示例代码

eoLinker-API_Shop_股票行情数据_API接口_Python调用示例代码

eoLinker-API Shop 股票行情数据 Python调用示例代码股票行情数据支持证券全市场行情数据,实时数据,K线数据,分笔数据,市场股票代码信息,历史数据等等,满足证券投资分析使用。

该产品拥有以下APIs:1.股票k线2.实时行情查询3.查询股票列表4.查询股票市场5.分笔6.分时查询7.指数实时报价8.组合行情查询9.综合排名注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=168申请API服务1.股票k线#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/kline"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码"period":"" #1:1分钟 2:5分钟 3:15分钟 4:30分钟 5:60分钟 6:日k 线 7:周k线 8:月k线"request_num":"" #请求行数"position_str":"" #定位串,默认-1 从头开始}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.实时行情查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/realtime"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.查询股票列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/list"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_type":"" #市场类别"request_num":"" #定位串,传空默认为20"position_str":"" #起始位空,从应答中获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')4.查询股票市场#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/market"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')5.分笔#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/tick"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码"request_num":"" #请求参数}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')6.分时查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/trend"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')7.指数实时报价#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/index"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')8.组合行情查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/comb"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_code":"" #股票代码}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')9.综合排名#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///mlhexpsz/stock/sort"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"stock_type":"" #股票类别,参考市场查询返回值"sort_type":"" #排序类别}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_区块链今日快讯_API接口_C#调用示例代码

eoLinker-API_Shop_区块链今日快讯_API接口_C#调用示例代码

eoLinker-API Shop 区块链今日快讯 C#调用示例代码区块链今日快讯包括比特币、以太坊等热门区块链信息以及最新的相关资讯,实时更新。

该产品拥有以下APIs:1.获取区块链快讯列表2.搜索区块链快讯注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=185申请API服务1.获取区块链快讯列表using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/coin/getNewsLi st";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("page", ""); //页码(默认为1)param.Add("pageSize", ""); //每页条数(范围[10,40],默认每页1 0条)Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.搜索区块链快讯using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/coin/searchNew s";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("keyword", ""); //搜索关键字param.Add("page", ""); //页码(默认为1)param.Add("pageSize", ""); //每页条数(范围[10,40],默认每页1 0条)Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。

eoLinker-API_Shop_猫咪大全_API接口_Python调用示例代码

eoLinker-API_Shop_猫咪大全_API接口_Python调用示例代码

eoLinker-API Shop 猫咪大全 Python调用示例代码猫咪大全可查询猫咪相关信息,包括品种介绍、产地、性格、寿命、价格等信息,带图片。

该产品拥有以下APIs:1.关键字获取猫类2.获取猫类列表3.获取猫类详细信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=193申请API服务1.关键字获取猫类#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/catFamily/queryCatListByKeyword" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #页码(默认为1)"pageSize":"" #当前页面猫咪数目(默认为30)"keyword":"" #关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.获取猫类列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/catFamily/queryCatList"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #页码(默认为1)"pageSize":"" #当前页面猫咪数目(默认为30)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.获取猫类详细信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/catFamily/queryCatInfo"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"petID":"" #猫猫ID}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_POI检索_API接口_Java调用示例代码

eoLinker-API_Shop_POI检索_API接口_Java调用示例代码

eoLinker-API Shop POI检索 Java调用示例代码POI检索通过关键词查询在某个地区的POI信息,支持市级、区县级查询:比如在广州查询“银行”,接口将会输出所有银行的地理信息列表。

该产品拥有以下APIs:1.POI搜索2.周边POI搜索3.POI多边形搜索注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=97申请API服务1.POI搜索package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String requestMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("keyWords", ""); //查询关键字(规则:多个关键字用“|”分割若不指定city,并且搜索的为泛词(例如“美食”)的情况下,返回的内容为城市列表以及此城市内有多少结果符合要求。

eoLinker-API_Shop_标准体重计算器_API接口_Java调用示例代码

eoLinker-API_Shop_标准体重计算器_API接口_Java调用示例代码

eoLinker-API Shop 标准体重计算器 Java调用示例代码标准体重计算器身体质量指数 (Body Mass Index, 简称BMI), 通过身高和体重来计算您的身材是否标准该产品拥有以下APIs:1.计算BMI值2.获取标准体重参考注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=104申请API服务1.计算BMI值package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("weight", ""); //体重(单位:千克/公斤)params.put("height", ""); //身高(单位:厘米/cm)String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}2.获取标准体重参考package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println("发送请求失败");}}}。

eoLinker-API_Shop_银行卡信息查询(含归属地)_API接口_PHP调用示例代码

eoLinker-API_Shop_银行卡信息查询(含归属地)_API接口_PHP调用示例代码

eoLinker-API Shop 银行卡信息查询(含归属地) PHP调用示例代码银行卡信息查询(含归属地)支持超30家主流银行归属地查询;支持国内外1200多家银行的银行卡信息查询,返回发卡行、编号、卡种、客服电话、卡样、官网、 Logo等信息,及时更新。

该产品拥有以下APIs:1.查询银行卡信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=191申请API服务1.查询银行卡信息<?php$method = "POST";$url = "https:///common/bank/queryCardDetail";$headers = NULL;$params = array("apiKey"=>"your_api_key", //需要从获取"bankcard"=>"", //银行卡号);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}。

eoLinker-API_Shop_快递物流查询_API接口_C#调用示例代码

eoLinker-API_Shop_快递物流查询_API接口_C#调用示例代码

eoLinker-API Shop 快递物流查询 C#调用示例代码快递物流查询自动识别快递公司,提供包括申通、顺丰、圆通、韵达、中通、汇通、EMS、天天、国通、德邦、宅急送等几百家快递物流公司单号查询接口。

该产品拥有以下APIs:1.获取快递公司2.查询快递信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=103申请API服务1.获取快递公司using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/express/getExp ressCompany";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.查询快递信息using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/express/getExp ressInfo";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("expressNumber", ""); //快递单号param.Add("expressType", ""); //快递公司,不填默认自动识别Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。

eoLinker-API_Shop_电视节目_API接口_PHP调用示例代码

eoLinker-API_Shop_电视节目_API接口_PHP调用示例代码

eoLinker-API Shop 电视节目 PHP调用示例代码电视节目央视及各地卫视的电视节目时间表,包括本周及下周的电视节目内容该产品拥有以下APIs:1.获取电视台分类2.获取电视频道3.获取电视节目的详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=129申请API服务1.获取电视台分类<?php$method = "POST";$url = "https:///common/tv/queryCategory";$headers = NULL;$params = array();$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim");foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}2.获取电视频道<?php$method = "POST";$url = "https:///common/tv/queryTVChannel";$headers = NULL;$params = array("categoryName"=>"" //频道分类名称(从获取频道分类接口获得,如“央视”));$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}3.获取电视节目的详情<?php$method = "POST";$url = "https:///common/tv/queryTVProgram";$headers = NULL;$params = array("id"=>"" //频道ID(从获取频道接口获得)"date"=>"" //日期(格式:yyyy-mm-dd,如“2017-09-27”),默认当天);$result = apishop_curl($method, $url, $headers, $params);If ($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000, 说明请求成功echo "请求成功:" . $result["body"];} else {//状态码非000000, 说明请求失败echo "请求失败:" . $result["body"];}} else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/*** 转发请求到目的主机* @param $method string 请求方法* @param $URL string 请求地址* @param null $headers 请求头* @param null $param 请求参数* @return array|bool*/function apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL) {// 初始化请求$require = curl_init($URL);// 判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;// 设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {// 跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);// 检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {// 设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}// 返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);// 重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);// 把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);// 发送请求$response = curl_exec($require);// 获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);// 关闭请求curl_close($require);if ($response) {// 返回头部字符串$header = substr($response, 0, $headerSize);// 返回体$body = substr($response, $headerSize);// 过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);// 将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim"); foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders, "body" => $body);} else {return FALSE;}}。

eoLinker-API_Shop_快递物流查询_API接口_Python调用示例代码

eoLinker-API_Shop_快递物流查询_API接口_Python调用示例代码

eoLinker-API Shop 快递物流查询 Python调用示例代码快递物流查询自动识别快递公司,提供包括申通、顺丰、圆通、韵达、中通、汇通、EMS、天天、国通、德邦、宅急送等几百家快递物流公司单号查询接口。

该产品拥有以下APIs:1.获取快递公司2.查询快递信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=103申请API服务1.获取快递公司#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/express/getExpressCompany" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.查询快递信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/express/getExpressInfo"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"expressNumber":"" #快递单号"expressType":"" #快递公司,不填默认自动识别}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_京东热词查询_API接口_Java调用示例代码

eoLinker-API_Shop_京东热词查询_API接口_Java调用示例代码

eoLinker-API Shop 京东热词查询 Java调用示例代码京东热词查询京东商品关键词搜索排名查询工具,可根据任意商品关键词,全站实时获取,搜索关注度最高的商品关键词,协助商家及时掌握:买家搜索习惯和买家需求。

该产品拥有以下APIs:1.京东热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=211申请API服务1.京东热搜查询package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("keyword", ""); //搜索关键字String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}。

eoLinker-API_Shop_周公解梦_API接口_Python调用示例代码

eoLinker-API_Shop_周公解梦_API接口_Python调用示例代码

eoLinker-API Shop 周公解梦 Python调用示例代码周公解梦周公解梦大全,周公解梦查询,免费周公解梦。

该产品拥有以下APIs:1.获取梦的类型2.通过类型获取解梦的详情3.搜索解梦详情注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=126申请API服务1.获取梦的类型#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/dream/getDreamTypes"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.通过类型获取解梦的详情#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/dream/queryDreamDetailByType" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"type":"" #梦的类型(从获取梦的类型接口获得)"page":"" #页码"pageSize":"" #每页条数(最多20条,默认10)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.搜索解梦详情#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/dream/searchDreamDetail"headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_常见疾病查询_API接口_Python调用示例代码

eoLinker-API_Shop_常见疾病查询_API接口_Python调用示例代码

eoLinker-API Shop 常见疾病查询 Python调用示例代码常见疾病查询提供所患疾病的病因、症状、检查、用药、治疗、并发症等方面的详细分析资料该产品拥有以下APIs:1.获取疾病部位列表2.通过部位获取疾病列表3.关键字获取疾病列表4.获取疾病列表5.查询疾病信息6.通过症状获取疾病列表注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=215申请API服务1.获取疾病部位列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseSiteList" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')2.通过部位获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListBySite" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)"site":"" #发病部位}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')3.关键字获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListByKeyword "headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)"keyword":"" #关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')4.获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseList" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"page":"" #当前页码(默认1)"pageSize":"" #该页疾病数量(默认15)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')5.查询疾病信息#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseInfo" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"diseaseID":"" #疾病ID}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')6.通过症状获取疾病列表#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/disease/queryDiseaseListBySymptom "headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"symptom":"" #症状,多个症状间用空格隔开"page":"" #当前页面(默认1)"pageSize":"" #该页疾病数量(默认15)}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码

eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码

eoLinker-API Shop 万智卡卡牌查询 C#调用示例代码万智卡卡牌查询获取炉万智牌信息,可获取全部,也可根据关键字查询某卡牌。

该产品拥有以下APIs:1.关键字获取卡牌列表2.获取卡牌列表3.获取卡牌信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=204申请API服务1.关键字获取卡牌列表using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/magicCard/quer yCardListByKeyword";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("keyword", ""); //关键字param.Add("page", ""); //当前页码(默认1)param.Add("pageSize", ""); //当前页面卡牌数量(默认30)Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.获取卡牌列表using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/magicCard/quer yCardList";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("page", ""); //当前页码(默认1)param.Add("pageSize", ""); //当前页面卡牌数量(默认30)Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}3.获取卡牌信息using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///common/magicCard/quer yCardInfo";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("cardID", ""); //卡牌IDDictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。

eoLinker-API_Shop_京东热词查询_API接口_Python调用示例代码

eoLinker-API_Shop_京东热词查询_API接口_Python调用示例代码

eoLinker-API Shop 京东热词查询 Python调用示例代码京东热词查询京东商品关键词搜索排名查询工具,可根据任意商品关键词,全站实时获取,搜索关注度最高的商品关键词,协助商家及时掌握:买家搜索习惯和买家需求。

该产品拥有以下APIs:1.京东热搜查询注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=211申请API服务1.京东热搜查询#!/usr/bin/env python# -*- coding: utf-8 -*-# 测试环境: python2.7# 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖import requestsimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')def apishop_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 Nonemethod = "POST"url = "https:///common/shopping/queryJDRelatedHotWords" headers = Noneparams = {"apiKey":"your_api_key", #需要从获取"keyword":"" #搜索关键字}result = apishop_send_request(method=method, url=url, params=params, he aders=headers)if result:body = result.textresponse = json.loads(body)status_code = response["statusCode"]if (status_code == '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,))else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,))else:# 返回内容异常,发送请求失败print('发送请求失败')。

eoLinker-API_Shop_股票行情数据_API接口_C#调用示例代码

eoLinker-API_Shop_股票行情数据_API接口_C#调用示例代码

eoLinker-API Shop 股票行情数据 C#调用示例代码股票行情数据支持证券全市场行情数据,实时数据,K线数据,分笔数据,市场股票代码信息,历史数据等等,满足证券投资分析使用。

该产品拥有以下APIs:1.股票k线2.实时行情查询3.查询股票列表4.查询股票市场5.分笔6.分时查询7.指数实时报价8.组合行情查询9.综合排名注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=168申请API服务1.股票k线using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers)string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt{using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/kline"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //股票代码param.Add("period", ""); //1:1分钟 2:5分钟 3:15分钟 4:30分钟 5:60分钟 6:日k线 7:周k线 8:月k线param.Add("request_num", ""); //请求行数param.Add("position_str", ""); //定位串,默认-1 从头开始Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}2.实时行情查询using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/realti me";Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //股票代码Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}3.查询股票列表using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/list"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_type", ""); //市场类别param.Add("request_num", ""); //定位串,传空默认为20 param.Add("position_str", ""); //起始位空,从应答中获取Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}4.查询股票市场using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/market ";Dictionary<string, string> param = new Dictionary<string, string>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}5.分笔using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/tick"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //股票代码param.Add("request_num", ""); //请求参数Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}6.分时查询using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value);}paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/trend"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //股票代码Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}7.指数实时报价using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/index"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //代码Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}8.组合行情查询using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/comb"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_code", ""); //股票代码Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Respo nse>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}9.综合排名using System;using System.Collections.Generic;using System.IO;using ;using System.Text;using System.Web.Script.Serialization;namespace apishop_sdk{class Program{/*** 转发请求到目的主机* @param method string 请求方法* @param url string 请求地址* @param params Dictionary<string,string> 请求参数* @param headers Dictionary<string,string> 请求头* @return string**/static string apishop_send_request(string method, string url, D ictionary<string, string> param, Dictionary<string, string> headers){string result = string.Empty;try{string paramData = "";if (param != null && param.Count > 0){StringBuilder sbuilder = new StringBuilder();foreach (var item in param){if (sbuilder.Length > 0){sbuilder.Append("&");}sbuilder.Append(item.Key + "=" + item.Value); }paramData = sbuilder.ToString();}method = method.ToUpper();if (method == "GET"){url = string.Format("{0}?{1}", url, paramData);}HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C reate(url);if (method == "GET"){wbRequest.Method = "GET";}else if (method == "POST"){wbRequest.Method = "POST";wbRequest.ContentType = "application/x-www-form-url encoded";wbRequest.ContentLength = Encoding.UTF8.GetByteCoun t(paramData);using (Stream requestStream = wbRequest.GetRequestS tream()){using (StreamWriter swrite = new StreamWriter(r equestStream)){swrite.Write(paramData);}}}HttpWebResponse wbResponse = (HttpWebResponse)wbRequest. GetResponse();using (Stream responseStream = wbResponse.GetResponseSt ream()){using (StreamReader sread = new StreamReader(respon seStream)){result = sread.ReadToEnd();}}}catch{return "";}return result;}class Response{public string statusCode;}static void Main(string[] args){string method = "POST";string url = "https:///mlhexpsz/stock/sort"; Dictionary<string, string> param = new Dictionary<string, s tring>();param.Add("apiKey", "your_api_key"); //需要从www.apishop.ne t获取param.Add("stock_type", ""); //股票类别,参考市场查询返回值param.Add("sort_type", ""); //排序类别Dictionary<string, string> headers = null;string result = apishop_send_request(method, url, param, he aders);if (result == ""){//返回内容异常,发送请求失败Console.WriteLine("发送请求失败");return;}Response res = new JavaScriptSerializer().Deserialize<Response>(result);if (res.statusCode == "000000"){//状态码为000000, 说明请求成功Console.WriteLine(string.Format("请求成功: {0}", resul t));}else{//状态码非000000, 说明请求失败Console.WriteLine(string.Format("请求失败: {0}", resul t));}Console.ReadLine();}}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

eoLinker-API Shop 猫咪大全 Java调用示例代码猫咪大全可查询猫咪相关信息,包括品种介绍、产地、性格、寿命、价格等信息,带图片。

该产品拥有以下APIs:1.关键字获取猫类2.获取猫类列表3.获取猫类详细信息注意,该示例代码仅适用于网站下API使用该产品前,您需要通过https:///#/api/detail/?productID=193申请API服务1.关键字获取猫类package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("page", ""); //页码(默认为1)params.put("pageSize", ""); //当前页面猫咪数目(默认为30)params.put("keyword", ""); //关键字String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}2.获取猫类列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("page", ""); //页码(默认为1)params.put("pageSize", ""); //当前页面猫咪数目(默认为30)String result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}3.获取猫类详细信息package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*** httpUrlConnection访问远程接口工具*/public class Api{/*** 方法体说明:向远程接口发起请求,返回字节流类型结果* param url 接口地址* param requestMethod 请求方式* param params 传递参数重点:参数值需要用Base64进行转码* return InputStream 返回结果*/public static InputStream httpRequestToStream(String url, String re questMethod, Map<String, String> params){InputStream is = null;try{String parameters = "";boolean hasParams = false;// 将参数集合拼接成特定格式,如name=zhangsan&age=24for (String key : params.keySet()){String value = URLEncoder.encode(params.get(key), "UTF-8");parameters += key + "=" + value + "&";hasParams = true;}if (hasParams){parameters = parameters.substring(0, parameters.length() - 1);}// 请求方式是否为getboolean isGet = "get".equalsIgnoreCase(requestMethod);// 请求方式是否为postboolean isPost = "post".equalsIgnoreCase(requestMethod);if (isGet){url += "?" + parameters;}URL u = new URL(url);HttpURLConnection conn = (HttpURLConnection) u.openConnecti on();// 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Con tent-Type为“”空)conn.setRequestProperty("Content-Type", "application/octet-stream");// conn.setRequestProperty("Content-Type", "application/x-w ww-form-urlencoded");// 设置连接超时时间conn.setConnectTimeout(50000);// 设置读取返回内容超时时间conn.setReadTimeout(50000);// 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认falseif (isPost){conn.setDoOutput(true);}// 设置从HttpURLConnection对象读入,默认为trueconn.setDoInput(true);// 设置是否使用缓存,post方式不能使用缓存if (isPost){conn.setUseCaches(false);}// 设置请求方式,默认为GETconn.setRequestMethod(requestMethod);// post方式需要将传递的参数输出到conn对象中if (isPost){DataOutputStream dos = new DataOutputStream(conn.getOut putStream());dos.writeBytes(parameters);dos.flush();dos.close();}// 从HttpURLConnection对象中读取响应的消息// 执行该语句时才正式发起请求is = conn.getInputStream();}catch(UnsupportedEncodingException e){e.printStackTrace();}catch(MalformedURLException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}return is;}public static void main(String args[]){String url = "https:///common/postcode/getPostCo deByAddr";String requestMethod = "POST";Map<String, String> params = new HashMap<String, String>(); params.put("apiKey","your_api_key"); //需要从获取params.put("petID", ""); //猫猫IDString result = null;try{InputStream is = httpRequestToStream(url, requestMethod, pa rams);byte[] b = new byte[is.available()];is.read(b);result = new String(b);}catch(IOException e){e.printStackTrace();}if (result != null){JSONObject jsonObject = JSONObject.parseObject(result);String status_code = jsonObject.getString("statusCode");if (status_code == "000000"){// 状态码为000000, 说明请求成功System.out.println("请求成功:" + jsonObject.getString("resu lt"));}else{// 状态码非000000, 说明请求失败System.out.println("请求失败:" + jsonObject.getString("desc "));}}else{// 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改System.out.println("发送请求失败");}}}。

相关文档
最新文档