yuanyongyao79 2005年03月23日
一段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没有收到,但是找不到什么原因,请各位老大帮我看看,这段代码有没有写错?
...全文
20 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
Java EE
创建于2007-09-28

3.7w+

社区成员

22.5w+

社区内容

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区公告
暂无公告