读书人

httpclient 提交xml解决办法

发布时间: 2012-01-16 23:36:51 作者: rapoo

httpclient 提交xml
我知道访问的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

读书人网 >J2SE开发

热点推荐