在线等,急......java 调用.net webservice 500错误

yinhangzhe 2015-11-25 03:55:06
原代码如下
package test;

import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* 通过UrlConnection调用Webservice服务
*
*/
public class Test2 {

public static void main(String[] args) throws Exception {
//服务的地址
URL wsUrl = new URL("http://192.168.1.100:8090/WSCurrTransfer.asmx?op=CurrTransfer");

HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();

conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");

conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
// conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
OutputStream os = conn.getOutputStream();

//请求体
//String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:q0=\"http://ws.itcast.cn/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
// "<soapenv:Body> <q0:sayHello><arg0>aaa</arg0> </q0:sayHello> </soapenv:Body> </soapenv:Envelope>";


String soap = "reqData=<?xml version=\"1.0\" encoding=\"GBK\" ?><root><TransFlag>111</TransFlag><BankSeqNo></BankSeqNo><BankCardNo>1111</BankCardNo><HodoCardNo></HodoCardNo><IDNumber></IDNumber><Name></Name><Money></Money><Remarks></Remarks><ReturnFlag></ReturnFlag></root>";

os.write(soap.getBytes());

InputStream is = conn.getInputStream();

byte[] b = new byte[1024];
int len = 0;
String s = "";
while((len = is.read(b)) != -1){
String ss = new String(b,0,len,"UTF-8");
s += ss;
}
System.out.println(s);

is.close();
os.close();
conn.disconnect();
}

}
...全文
86 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yinhangzhe 2015-11-25
报错信息 在 InputStream is = conn.getInputStream() Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://172.22.0.92:8090/WSCurrTransfer.asmx?op=CurrTransfer at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626) at test.Test2.main(Test2.java:39)
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-11-25 03:55
社区公告
暂无公告