java如何调用对方http接口 新手虚心求教

tangqinghan0812 2015-09-23 03:43:20
对方给出的接口文档的方法 http://www.anjismart.com:7770/QueryCodeService.asmx?op=QueryCode
想要做一个在自己网站上能查到的防伪验证 求教在jsp页面上要写什么java页面上些什么,应该要写哪些东西,或者有个类似的学习例子也好
-------------------------------------------------------------------------------------------------------------
HTTP GET
以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。

GET /QueryCodeService.asmx/QueryCode?code=string&aid=string HTTP/1.1
Host: www.anjismart.com

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.anjismart.com/">string</string>
-----------------------------------------------------------------------------------------------------------------------------------
1.1接口地址http://www.anjismart.com:7770/QueryCodeService.asmx/QueryCode?code=***************&aid=302
1.2http请求方式
Get
1.3参数列表
参数 是否必须 说明
code 是 需要被查询的防伪码。
aid 是 查询通道号使用302号通道。请严格填写,否则可能会遭到系统自动屏蔽!
1.4返回说明
正常情况下,系统会返回如下
[RESULT];[FIRSTQUETYDATE]

参数 说明
RESULT 查询结果:
0:首次查询
1-9:多次查询(当查询次数大于等于10时,返回结构为9.)
?:防伪码位数错误或格式错误。
-:未找到的防伪码。
j:被系统注销的防伪码。
FIRSTQUETYDATE 改号码首次被查询时间,若本次查询即为首次查询,则返回12位0。

若发生错误返回格式如下
error;[ERRORREASON]

参数 说明
ERRORREASON 错误原因(可能不存在):
Error code length!
提交的防伪码长度错误。
There is error word(s) in the code!
提交的防伪码中存在非法内容。

1.5请求实例
http://www.anjismart.com:7770/QueryCodeService.asmx/QueryCode?code=425144174493800&aid=302
1.6返回实例
首次查询
0:000000000000
非首次查询
1:201501131516
...全文
38252 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
aishow_forever 2017-08-17
  • 打赏
  • 举报
回复
看到上面的回帖,我笑疯了。一个是2015年留言的帖子,然后2017年的才留下邮箱,我滴个乖乖,想想也不可能看到你们留下的邮箱地址发给你们的,好人没用。
knor_ 2017-08-04
  • 打赏
  • 举报
回复
能否也发一份给我...429223901@qq.com ,谢谢
qinontheway 2017-05-18
  • 打赏
  • 举报
回复
934925404@qq.com能否也发一份给我谢谢
you_lhf 2017-04-20
  • 打赏
  • 举报
回复
引用 2 楼 caolong0210 的回复:

/**
	 * 程序中访问http数据接口
	 */
	public static String getURLContent(String urlStr) {
		/** 网络的url地址 */
		URL url = null;
		/** http连接 */
		HttpURLConnection httpConn = null;
		/**//** 输入流 */
		BufferedReader in = null;
		StringBuffer sb = new StringBuffer();
		try {
			url = new URL(urlStr);
			in = new BufferedReader(new InputStreamReader(url.openStream(), "GBK"));
			String str = null;
			while ((str = in.readLine()) != null) {
				sb.append(str);
			}
		} catch (Exception ex) {

		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
			}
		}
		String result = sb.toString();
		System.out.println(result);
		return result;
	}
确定这代码在jdk1.7和1.6上的执行是一样的么?
二黑黑黑 2017-03-13
  • 打赏
  • 举报
回复
引用 6 楼 baidu_31006959 的回复:
楼主能否提供下邮箱,我给你发个工具类,这里的接口完全可以符合你的要求。
可以给我发个吗 qq邮箱1294813587@qq.com
yuqi_hz 2017-01-05
  • 打赏
  • 举报
回复
去看下httpClient,很简单
qq_35307470 2017-01-05
  • 打赏
  • 举报
回复
zhangjunhevip@sina.com 发一份 谢谢好人
baidu_31006959 2015-09-24
  • 打赏
  • 举报
回复
楼主能否提供下邮箱,我给你发个工具类,这里的接口完全可以符合你的要求。
dw_java08 2015-09-23
  • 打赏
  • 举报
回复
给你一个访问微信接口方法代码,你看看 ... public static final String reqPath = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN"; // 连接微信接口,群发消息 public static JSONObject connectWeiXinInterface(String reqPath, String json) { URL url; String result = ""; JSONObject jsonObject = null; try { url = new URL(reqPath); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); http.setDoInput(true); http.setDoOutput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒 http.connect(); OutputStream os = http.getOutputStream(); os.write(json.getBytes("UTF-8"));// 传入参数 InputStream is = http.getInputStream(); int size = is.available(); byte[] b = new byte[size]; is.read(b); result = new String(b, "UTF-8"); log.info("请求返回结果:" + result); jsonObject = JSONObject.fromObject(result); os.flush(); os.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return jsonObject; } ...
解开者 2015-09-23
  • 打赏
  • 举报
回复
建议用httpclient包,它对通信有一些封装,不再是裸露的流的形式,也比较容易获得对方返回的状态
风若飞 2015-09-23
  • 打赏
  • 举报
回复
对方现在给你的soap接口,你需要简历webservice的客户端来请求连接。具体webservcie怎么生成,你在百度去吧。
哎呦喂哈 2015-09-23
  • 打赏
  • 举报
回复

/**
	 * 程序中访问http数据接口
	 */
	public static String getURLContent(String urlStr) {
		/** 网络的url地址 */
		URL url = null;
		/** http连接 */
		HttpURLConnection httpConn = null;
		/**//** 输入流 */
		BufferedReader in = null;
		StringBuffer sb = new StringBuffer();
		try {
			url = new URL(urlStr);
			in = new BufferedReader(new InputStreamReader(url.openStream(), "GBK"));
			String str = null;
			while ((str = in.readLine()) != null) {
				sb.append(str);
			}
		} catch (Exception ex) {

		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
			}
		}
		String result = sb.toString();
		System.out.println(result);
		return result;
	}
tony4geek 2015-09-23
  • 打赏
  • 举报
回复
String strURL = "http://www.anjismart.com:7770/QueryCodeService.asmx/QueryCode?code=425144174493800&aid=302";
		 URL url = new URL(strURL);
		 HttpURLConnection httpConn = (HttpURLConnection)
		 url.openConnection();
		 httpConn.setRequestMethod("GET");
		 httpConn.connect();
			
		 BufferedReader reader = new BufferedReader(new InputStreamReader(
		 httpConn.getInputStream()));
		 String line;
		 StringBuffer buffer = new StringBuffer();
		 while ((line = reader.readLine()) != null) {
		 buffer.append(line);
		 }
		 reader.close();
		 httpConn.disconnect();
		 
	    System.out.println(buffer.toString());

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧