不得不成文httpclient是有些毛病的
比如,在不同的环境中的表现不同。经历过的就是测试环境是发http1.0协议,到了生产就默认使用http1.1了。
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
强制转为1.1也不行。怎么办,网上搜罗了一大堆废话,,,再试试
HttpPost httppost = new HttpPost(configContext.getAccConf().get(system)
.getACCESS_PATH());
httppost.setConfig(requestConfig); // 设置配置
httppost.setProtocolVersion(HttpVersion.HTTP_1_1);
操,这个也是不行。
我能怎么办,我还能怎么办,踢掉httpclient呗
URL u = new URL(configContext.getAccConf().get(system)
.getACCESS_PATH());
connection = (HttpURLConnection)u.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setReadTimeout(60000);
connection.setConnectTimeout(5000);
connection.connect();
long startTime = System.currentTimeMillis();
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.write(b);
out.flush();
out.close();
原僧妈的。这下统一了,不管什么环境都是使用Http1.1了。
尼玛折腾了一天时间,我也不太懂httpclient到底是怎么回事。有懂的大牛希望能解释下