高手请帮帮忙!
解决方案 »
- tomcat里的日志 localhost.***.log中报的一个错误,看不懂,Cannot call sendError() after the respon
- 登录验证码
- 利用HSQLDB 进行Hibernate单元测试
- jsp 文本显示位置错乱
- jquery插件uploadify如何判断上传的类型
- java做QQ机器人
- 将info和error分别记录到对应的日志文件info.log和error.log,大家有什么好办法?
- 怎么在JDON里揭贴?
- 哪位兄台了解国信朗讯公司
- mysql自动生成的自增ID会是已存在的!
- 大家帮我一下这个程序的错误,我弄了一天了也不对,希望各位帮帮忙,另外请问sql sever 2005的驱动包是什么及放在什么地方
- 请问大家个共通方法问题
http://hi.baidu.com/delete_h/blog/item/b6ae8359d8c5ce232934f013.html
把这个代码改改public void sendXML(String filePath,String _url) throws Exception{
String urlString = _url;
String xmlFile = filePath;
URL url = new URL(urlString); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();; File fileToSend=new File(xmlFile);
byte[] buf=new byte[(int)fileToSend.length()];
new FileInputStream(xmlFile).read(buf);
httpConn.setRequestProperty( "Content-Length",String.valueOf( buf.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction","××××××××");
httpConn.setRequestProperty("Accept","text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write( buf );
out.close();
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(),"utf-8");
BufferedReader in = new BufferedReader(isr);
String inputLine;
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("result.xml")));
while ((inputLine = in.readLine()) != null){
System.out.println(inputLine);
bw.write(inputLine);
bw.newLine();
}
bw.close();
in.close();
}
public static void main(String[] args) {
InputStream in = null;
OutputStream out = null;
try {
// Check the arguments
if ((args.length != 1)&& (args.length != 2))
throw new IllegalArgumentException("Wrong number of args");
// Set up the streams
URL url = new URL(args[0]); // Create the URL
in = url.openStream(); // Open a stream to it
if (args.length == 2) // Get an appropriate output stream
out = new FileOutputStream(args[1]);
else out = System.out;
// Now copy bytes from the URL to the output stream
byte[] buffer = new byte[4096];
int bytes_read;
while((bytes_read = in.read(buffer)) != -1)
out.write(buffer, 0, bytes_read);
}
// On exceptions, print error message and usage message.
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: java GetURL <URL> [<filename>]");
}
finally { // Always close the streams, no matter what.
try {
in.close();
out.close();
} catch (Exception e) {
}
}
}
}
String content = "";
try {
URL url = new URL(strUrl);
//得charset
String charset = SinoDetect.getInstance().getCharset(url);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.connect();
int code = uc.getResponseCode();
if(code != 200)
return content;
DataInputStream dis = new DataInputStream(uc.getInputStream());
InputStreamReader isr = new InputStreamReader(dis, charset);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
content += line.trim();
}
} catch (MalformedURLException e) {
System.out.println("getContent异常 1 : " + e.toString());
} catch (IOException e) {
System.out.println("getContent异常 2 : " + e.toString());
}
return content;
}