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 );
没有找到相关结果
已邀请:
2 个回复
扭湘阀柿蹄
功飘