一段java的net代码,请帮我看看有没有错?

yuanyongyao79 2005-03-23 04:16:56
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没有收到,但是找不到什么原因,请各位老大帮我看看,这段代码有没有写错?
...全文
55 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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