admin 管理员组

文章数量: 887030


2024年1月11日发(作者:难破mg5日剧)

基于JAVA的备案查询接口调用代码实例

代码描述:基于JAVA的备案查询接口调用代码实例

代码平台:聚合数据

import

edReader;

import

tputStream;

import

ption;

import

tream;

import

treamReader;

import

ortedEncodingException;

import

LConnection;

import

;

import

oder;

import

p;

import

;

import

ject;

/**

*域名备案查询调用示例代码 - 聚合数据

*在线接口文档:/docs/68

**/

public

class

JuheDemo {

public

static

final

String DEF_CHATSET = "UTF-8";

public

static

final

int

DEF_CONN_TIMEOUT = 30000;

public

static

final

int

DEF_READ_TIMEOUT = 30000;

public

static

String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";

//配置您申请的KEY

public

static

final

String APPKEY ="*************************";

//1.备案查询

public

static

void

getRequest1(){

String result =null;

String url ="/japi/beian";//请求接口地址

Map params = new

HashMap();//请求参数

("key",APPKEY);//应用APPKEY(应用详细页查询)

("type","");//0通过网站名称查询,如:聚合数据平台
1通过域名查询,如:
2通过网站首页查询,如
3通过许可证号查询查询,如:苏ICP备14006450号-3
5通过主办单位名称查询,如:苏州新科兰德科技有限公司

("keyword","");//对应type的值,如:

("v","");//版本号,固定1.0

try

{

result =net(url, params, "GET");

JSONObject object = ject(result);

if(("error_code")==0){

n(("result"));

}else{

n(("error_code")+":"+("reason"));

}

} catch

(Exception e) {

tackTrace();

}

}

public

static

void

main(String[] args) {

}

/**

*

* @param strUrl 请求地址

* @param params 请求参数

* @param method 请求方法

* @return 网络请求字符串

* @throws Exception

*/

public

static

String net(String strUrl, Map params,String method) throws

Exception {

HttpURLConnection conn = null;

BufferedReader reader = null;

String rs = null;

try

{

StringBuffer sb = new

StringBuffer();

if(method==null

|| ("GET")){

strUrl = strUrl+"?"+urlencode(params);

}

URL url = new

URL(strUrl);

conn = (HttpURLConnection) nnection();

if(method==null

|| ("GET")){

uestMethod("GET");

}else{

uestMethod("POST");

utput(true);

}

uestProperty("User-agent", userAgent);

Caches(false);

nectTimeout(DEF_CONN_TIMEOUT);

dTimeout(DEF_READ_TIMEOUT);

tanceFollowRedirects(false);

t();

if

(params!= null

&& ("POST")) {

try

{

DataOutputStream out = new

DataOutputStream(putStream());

ytes(urlencode(params));

} catch

(Exception e) {

// TODO: handle exception

}

}

InputStream is = utStream();

reader = new

BufferedReader(new

InputStreamReader(is, DEF_CHATSET));

String strRead = null;

while

((strRead = ne()) != null) {

(strRead);

}

rs = ng();

} catch

(IOException e) {

tackTrace();

} finally

{

}

if

(reader != null) {

();

}

if

(conn != null) {

nect();

}

}

return

rs;

//将map型转为请求参数型

public

static

String urlencode(Mapdata) {

StringBuilder sb = new

StringBuilder();

for

( i : et()) {

try

{

(()).append("=").append((ue()+"","UTF-8")).append("&");

} catch

(UnsupportedEncodingException e) {

tackTrace();

}

}

return

ng();

}

}


本文标签: 查询 请求 代码 接口 调用