POST命令之后是否可以忽略来自网络服务器的响应?

| 我正在用JAVA编写程序,以将大量XML文档发布到特定的Web地址,此外还有大量其他与该问题无关的数据处理。唯一的麻烦是,我希望可以处理大约90,000条记录。在发布XML文档时,每条记录大约需要10秒钟,其中9条是通过在POST之后收到来自服务器的响应而获得的。 我的问题是:有没有办法将数据发布到Web服务器,然后忽略服务器的响应以节省时间? 这是一个给我带来麻烦的代码片段,根据系统计时器,从\“ writer.close \”转到\“ con.getResponseCode()\”大约需要9秒钟
URL url = new URL(TargetURL);
con = (HttpsURLConnection) url.openConnection();


//Login with given credentials
String login = (Username)+\":\"+(Password);
String encoding = new sun.misc.BASE64Encoder().encode(login.getBytes());
con.setRequestProperty (\"Authorization\", \"Basic \" + encoding);

// specify that we will send output and accept input
con.setRequestMethod(\"POST\");
con.setDoInput(true);
con.setDoOutput(true);

con.setConnectTimeout(20000) ;  // long timeout, but not infinite
con.setReadTimeout(20000);

con.setUseCaches (false);
con.setDefaultUseCaches (false);

// tell the web server what we are sending
con.setRequestProperty ( \"Content-Type\", \"text/xml\" );

OutputStreamWriter writer = new OutputStreamWriter( con.getOutputStream() );
writer.write(data);
writer.flush();
writer.close();

//****This is our problem.*****//
int result = con.getResponseCode();                 
System.err.println( \"\\nResponse from server after POST:\\n\" + result );
    
已邀请:
        我明白你的问题。 使用该策略仅读取标头对您不起作用,因为问题不是由于服务器作为响应发送的海量数据。问题在于服务器需要很长时间来处理您的客户端已发送的数据,因此甚至需要很长时间才能发送简短的确认响应。 您要的是异步响应。答案是AJAX,我的首选是GWT。 GWT提供了三种与服务器进行异步通信的方式。 GWT RPC RequestBuilder javascript包括 MVP ClientFactory / EventBus 请阅读我的描述 http://h2g2java.blessedgeek.com/2009/08/gwt-rpc.html http://h2g2java.blessedgeek.com/2011/06/gwt-requestbuilder-vs-rpc-vs-script.html 但是,然后,您可能更喜欢使用JQuery,而我对JQuery的了解很少且很少。     
        我宁愿使用Apache HttpComponents。它使您无需阅读响应正文,而仅阅读您显然需要的标头。 http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d4e143 文档的那一部分有一个仅读取响应的几个字节的示例。     

要回复问题请先登录注册