一段java的net代码,请帮我看看有没有错?
public static void testProvision(String fName,String outfName) {
String serviceUrl = "http://localhost:8083/myServlet/pvy";
try {
URL url = new URL(serviceUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
if (httpConn == null) {
//System.out.println("the httpConn is null");
}
//read the soap message
//InputStream in = new Client().getClass().getResourceAsStream(soapFile);
InputStream in = new FileInputStream(fName);
if (in == null) {
//System.out.println("input stream is null");
}
//define byte output stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
//read the soap message content into bout
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int byteRead = in.read(buffer);
while (byteRead != -1) {
bout.write(buffer, 0, byteRead);
byteRead = in.read(buffer);
}
in.close();
byte[] b = bout.toByteArray();
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type","text/xml;charset=utf-8");
httpConn.setRequestProperty("SOAPAction","sg.UnSubscribeService");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
//write the soap message into http conn
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
//read out the response of http and out put
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader br = new BufferedReader(isr);
String inputLine;
out = new FileOutputStream(outfName);
while ( (inputLine = br.readLine()) != null) {
//System.out.println(inputLine);
out.write(inputLine.getBytes());
}
out.flush();
out.close();
br.close();
}
catch (Exception e) {
//System.out.println("SSSS" + e);
}
}
这段代码的目的是把硬盘上的一个xml文件通过url通道向serlvet传送过去,并从serlvet的response中取回另一段;
但是我运行这段代码后,发现servlet没有收到,但是找不到什么原因,请各位老大帮我看看,这段代码有没有写错?
String serviceUrl = "http://localhost:8083/myServlet/pvy";
try {
URL url = new URL(serviceUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
if (httpConn == null) {
//System.out.println("the httpConn is null");
}
//read the soap message
//InputStream in = new Client().getClass().getResourceAsStream(soapFile);
InputStream in = new FileInputStream(fName);
if (in == null) {
//System.out.println("input stream is null");
}
//define byte output stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
//read the soap message content into bout
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int byteRead = in.read(buffer);
while (byteRead != -1) {
bout.write(buffer, 0, byteRead);
byteRead = in.read(buffer);
}
in.close();
byte[] b = bout.toByteArray();
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type","text/xml;charset=utf-8");
httpConn.setRequestProperty("SOAPAction","sg.UnSubscribeService");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
//write the soap message into http conn
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
//read out the response of http and out put
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader br = new BufferedReader(isr);
String inputLine;
out = new FileOutputStream(outfName);
while ( (inputLine = br.readLine()) != null) {
//System.out.println(inputLine);
out.write(inputLine.getBytes());
}
out.flush();
out.close();
br.close();
}
catch (Exception e) {
//System.out.println("SSSS" + e);
}
}
这段代码的目的是把硬盘上的一个xml文件通过url通道向serlvet传送过去,并从serlvet的response中取回另一段;
但是我运行这段代码后,发现servlet没有收到,但是找不到什么原因,请各位老大帮我看看,这段代码有没有写错?
...全文
相关推荐
JAVA 用 Apache CXF 调用 .NET 服务端 WebService 代码
JAVA 用 Apache CXF 调用 .NET 服务端 WebService 代码 整个JAVA工程的压缩,导入到myeclipse可直接运行,如果只想浏览下,请访问:http://blog.csdn.net/wqmain/article/details/8216331
asp.net通过WebService调用Java接口全过程
asp.net通过WebService调用Java接口全过程。 asp.net---->WebService(SOAP)------>Java接口---->Java接口实现类------>RMI(Java远程方法调用)----->RMI服务器端------->RMI返回结果给asp.net
.NET和JAVA的比较
是我自己总结的c#和java的语言的若干区别 当然随着java的发展,可能有些区别已经消失了
VB.NET转JAVA工具
VB.net转换成JAVA的工具。包含说明和源代码。
.net写的java代码生成工具
本软件生成Struts2.1.8,Spring2.5,Hibernate3代码。 生成实体类,Dao层,Biz层,Action,Jsp页面,struts.xml,applicationcontext.xml,hibernate.cfg.xml,web.xml。 支持关系映射。绿盟评论:生成Java代码工具用.net写的,作者真牛,哈哈。 若想更好的利用此软件加快开发效率,减少成本,请遵循Hibernate规范。


