我知道访问的url、id、password,需要把生成的xml以stream的形式post过去,但是我使用了以下方法,始终给我connection time out的错误。请教高手。
public boolean postXMLData(InputStream istream){
//Logger.logMsg(className+ "> > > > > > > > > postXMLData:begin........... ");
boolean flag=false;
HttpClient client = new HttpClient();
PostMethod post = new PostMethod( "http://……/receiveXML ");
UsernamePasswordCredentials upc = new UsernamePasswordCredentials( "id ", "pswd ");
client.getState().setCredentials(AuthScope.ANY,upc);
try{
post.setDoAuthentication(true);
post.setRequestBody(istream);
post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
post.setRequestHeader( "Content-type ", "text/xml; charset=GBK ");
System.out.println( "连接成功 ");
client.executeMethod(post);
System.out.println( "传输成功 ");
post.releaseConnection();
flag=true;
} catch (Exception e1) {
logger.error( "Exception from method postXMLData() e1 -> " + e1);
}finally {
post.releaseConnection();
}
//Logger.logMsg(className+ "> > > > > > > > > postXMLData:end........... ");
return flag;
}
------解决方案--------------------
post.releaseConnection(); 执行两次
------解决方案--------------------
无法连接到http://……/receiveXML