JAVA如何调用对方http接口得到返回数据
来源:互联网 发布:勇士雷霆g5数据 编辑:程序博客网 时间:2024/05/20 23:33
http://www.anjismart.com:7770/QueryCodeService.asmx/QueryCode?code=425144174493800&aid=302
浏览器访问该链接的数据:
<?xml version="1.0" encoding="UTF-8"?><string xmlns="http://www.anjismart.com/">j</string>通过JAVA代码如何访问:
package com.accord.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;public class Test {public static void main(String[] args) throws Exception {//方法一//System.out.println((new Test()).getURLContent());String urlStr = "http://www.anjismart.com:7770/QueryCodeService.asmx/QueryCode?code=425144174493800&aid=302";System.out.println((new Test()).getURLContent(urlStr));}public static String getURLContent() throws Exception {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()); return buffer.toString();}/** * 程序中访问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;}}
阅读全文
0 0
- JAVA如何调用对方http接口得到返回数据
- 连接对方接口得到格式xml数据
- java如何调用http接口
- JAVA后台调用接口并得到返回值
- 调用接口返回数据
- Java http协议调用接口返回json字符串
- java调用http接口并解析返回的json对象
- 如何调用http接口获取json数据及GET/POST方式调用http接口
- JAVA 请求http接口返回json数据解析
- java调用http接口
- java调用http接口
- 【Java】调用http接口
- java 调用http接口
- java调用http接口
- java调用http接口
- 调用远程接口,返回数据
- java 调用 shell 得到返回值(二)
- java 调用 linux命令 得到返回值
- Android增量更新(三)-差分文件(Linux)-生成jar和.so库
- JS--利用数组写九九乘法表
- [Android]自己动手做个拼图游戏
- 协程
- 分析 ddp rdma 模块
- JAVA如何调用对方http接口得到返回数据
- Struts2学习(三)【主配置文件配置_常量配置_动态方法配置_action书写方式】
- JS将值转化成字符串的方法
- 动态设置线程栈大小
- XP系统怎样备份注册表
- Android pulltorefresh上拉下拉刷新加载
- Struts2学习(四)【结果跳转方式】
- Leetcode-Best Time to Buy and Sell Stock
- Jmeter乱码