使用URLConnection访问Web Service

wlj19901115001 2011-10-24 04:52:01
接口是这个:http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx?disco
我想实现URLConnection访问该Web Service,但是我真的不知道这个Web Service的地址该怎么用?
我想请教大家帮忙一个小列子就可以。
...全文
146 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjwxg1008 2011-10-25
  • 打赏
  • 举报
回复
	try {

String url ="http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx?disco";
HttpClient client = new HttpClient();
// String params = "";
HttpMethod method = new GetMethod(url);
// method.setQueryString(params); //params 为访问参数 System.out.println(method);
client.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
//返回访问结果
String response = method.getResponseBodyAsString();
System.out.println(response);
}
method.releaseConnection();
} catch (HttpException e) {
// TODO Auto-generated catch block
System.out.println("访问失败!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("返回失败!");
result = "0.00";
e.printStackTrace();
}


wlj19901115001 2011-10-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zjwxg1008 的回复:]
Java code
try {

String url ="http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx?disco";
HttpClient client = new HttpClient();
// Strin……
[/Quote]
谢谢分享。

81,091

社区成员

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

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