对方给出的接口文档的方法  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.comHTTP/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

解决方案 »

  1.   

    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());
      

  2.   


    /**
     * 程序中访问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;
    }
      

  3.   

    对方现在给你的soap接口,你需要简历webservice的客户端来请求连接。具体webservcie怎么生成,你在百度去吧。
      

  4.   

    建议用httpclient包,它对通信有一些封装,不再是裸露的流的形式,也比较容易获得对方返回的状态
      

  5.   

    给你一个访问微信接口方法代码,你看看
    ...
     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;
    }
    ...
      

  6.   

    [email protected]  发一份 谢谢好人
      

  7.   

    去看下httpClient,很简单
      

  8.   


    确定这代码在jdk1.7和1.6上的执行是一样的么?