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

yuanyongyao79 yuanyongyao79 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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没有收到,但是找不到什么原因,请各位老大帮我看看,这段代码有没有写错?
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
yuanyongyao79
Java EE 67,535 成员 225,843 内容