- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
使用下面的测试类,/////1/////
处的行抛出一个 NoHttpResponseException
(请参阅末尾的日志记录异常跟踪问题)。执行任何其他行 /////2-to-8/////
可以很好地打印出标题。这是 HttpClient 4.3.x 中的错误还是我做错了什么(我已经用 4.3.1 和 4.3.2 测试过)?
import java.util.Arrays;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.params.*;
public class PrintHeaders {
private static final String MONEY_SMART_URL = "https://www.moneysmart.gov.au/";
private static final String TGA_URL = "https://www.ebs.tga.gov.au/ebs/picmi/picmirepository.nsf/PICMI?OpenForm&t=&k=P";
private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0";
public static void main(String[] args) throws Exception {
printHeadersByHead_4_3(TGA_URL); ///// 1 /////
// printHeadersByHead_4_2(TGA_URL); ///// 2 /////
// printHeadersByGet_4_3(TGA_URL); ///// 3 /////
// printHeadersByGet_4_2(TGA_URL); ///// 4 /////
// printHeadersByHead_4_3(MONEY_SMART_URL); ///// 5 /////
// printHeadersByHead_4_2(MONEY_SMART_URL); ///// 6 /////
// printHeadersByGet_4_3(MONEY_SMART_URL); ///// 7 /////
// printHeadersByGet_4_2(MONEY_SMART_URL); ///// 8 /////
}
public static void printHeadersByHead_4_3(String docURL) {
printHeaders(new HttpHead(docURL), buildHttpClient_4_3());
}
public static void printHeadersByHead_4_2(String docURL) {
printHeaders(new HttpHead(docURL), buildHttpClient_4_2());
}
public static void printHeadersByGet_4_3(String docURL) {
printHeaders(new HttpGet(docURL), buildHttpClient_4_3());
}
public static void printHeadersByGet_4_2(String docURL) {
printHeaders(new HttpGet(docURL), buildHttpClient_4_2());
}
public static void printHeaders(HttpRequestBase req, CloseableHttpClient client) {
CloseableHttpResponse response = null;
try {
try {
response = client.execute(req);
System.out.println(Arrays.asList(response.getAllHeaders()));
} finally {
if (response != null) response.close();
if (client != null) client.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static CloseableHttpClient buildHttpClient_4_3() {
return HttpClients.custom().setUserAgent(DEFAULT_USER_AGENT).build();
}
@SuppressWarnings("deprecation")
public static CloseableHttpClient buildHttpClient_4_2() {
AbstractHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, DEFAULT_USER_AGENT);
return httpClient;
}
}
Exception Trace when running line at /////1/////
:
2014/02/17 09:36:43:857 EST [DEBUG] RequestAddCookies - CookieSpec selected: best-match
2014/02/17 09:36:43:871 EST [DEBUG] RequestAuthCache - Auth cache not set in the context
2014/02/17 09:36:43:873 EST [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2014/02/17 09:36:43:890 EST [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
2014/02/17 09:36:43:902 EST [DEBUG] MainClientExec - Opening connection {s}->https://www.ebs.tga.gov.au:443
2014/02/17 09:36:44:046 EST [DEBUG] HttpClientConnectionManager - Connecting to www.ebs.tga.gov.au/161.146.233.4:443
2014/02/17 09:36:45:038 EST [DEBUG] MainClientExec - Executing request HEAD /ebs/picmi/picmirepository.nsf/PICMI?OpenForm&t=&k=P HTTP/1.1
2014/02/17 09:36:45:038 EST [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
2014/02/17 09:36:45:039 EST [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
2014/02/17 09:36:45:041 EST [DEBUG] headers - http-outgoing-0 >> HEAD /ebs/picmi/picmirepository.nsf/PICMI?OpenForm&t=&k=P HTTP/1.1
2014/02/17 09:36:45:041 EST [DEBUG] headers - http-outgoing-0 >> Host: www.ebs.tga.gov.au
2014/02/17 09:36:45:041 EST [DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive
2014/02/17 09:36:45:041 EST [DEBUG] headers - http-outgoing-0 >> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
2014/02/17 09:36:45:042 EST [DEBUG] headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2014/02/17 09:37:00:222 EST [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
2014/02/17 09:37:00:222 EST [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
2014/02/17 09:37:00:222 EST [DEBUG] MainClientExec - Connection discarded
2014/02/17 09:37:00:222 EST [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
2014/02/17 09:37:00:223 EST [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2014/02/17 09:37:00:224 EST [INFO] RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
2014/02/17 09:37:00:224 EST [DEBUG] RetryExec - The target server failed to respond <org.apache.http.NoHttpResponseException: The target server failed to respond>org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
at com.sun.proxy.$Proxy0.receiveResponseHeader(Unknown Source)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:253)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at PerformHttpHead.printHeaders(PrintHeaders.java:43)
at PerformHttpHead.printHeadersByHead_4_3(PrintHeaders.java:24)
at PerformHttpHead.main(PrintHeaders.java:13)
最佳答案
罪魁祸首原来是自动内容解压缩,它在 4.2 中默认关闭,在 4.3 中默认打开。 HEAD 请求中存在 Accept-Encoding: gzip,deflate
似乎会混淆 Lotus-Domino Web 服务器。
[DEBUG] RequestAddCookies - CookieSpec selected: best-match
[DEBUG] RequestAuthCache - Auth cache not set in the context
[DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 200]
[DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 200]
[DEBUG] MainClientExec - Opening connection {s}->https://www.ebs.tga.gov.au:443
[DEBUG] HttpClientConnectionOperator - Connecting to www.ebs.tga.gov.au/161.146.233.4:443
[DEBUG] HttpClientConnectionOperator - Connection established 192.168.42.63:40880<->161.146.233.4:443
[DEBUG] MainClientExec - Executing request HEAD / HTTP/1.1
[DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[DEBUG] headers - http-outgoing-0 >> HEAD / HTTP/1.1
[DEBUG] headers - http-outgoing-0 >> Host: www.ebs.tga.gov.au
[DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.3-SNAPSHOT (java 1.5)
[DEBUG] headers - http-outgoing-0 << HTTP/1.1 200 OK
[DEBUG] headers - http-outgoing-0 << Server: Lotus-Domino
[DEBUG] headers - http-outgoing-0 << Date: Tue, 18 Feb 2014 15:25:32 GMT
[DEBUG] headers - http-outgoing-0 << Content-Type: text/html
[DEBUG] headers - http-outgoing-0 << Content-Length: 15765
[DEBUG] headers - http-outgoing-0 << Expires: Thu, 01 Jan 1970 23:59:59 GMT
[DEBUG] headers - http-outgoing-0 << Cache-control : no-cache, no-store, private Pragma: Value: no-cache
[DEBUG] MainClientExec - Connection can be kept alive indefinitely
[DEBUG] PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://www.ebs.tga.gov.au:443] can be kept alive indefinitely
[DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://www.ebs.tga.gov.au:443][total kept alive: 1; route allocated: 1 of 100; total allocated: 1 of 200]
关于java - 使用 HttpClient 4.3.x,为特定 URL 执行 HttpHead 会给出 NoHttpResponseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21818242/
我在使用带有 vector STL 的迭代器时遇到了这个错误。 代码:- #include #include void print_vec(std::vector vec) { auto
JAVA:两个引用“p”&&“pp”之间有区别吗? PrintStream p = new PrintStream(System.out); p.println("lol");
我尝试从主分支中拉出,但收到错误消息: $ git --no-optional-locks -c color.branch=false -c color.diff=false -c color.sta
我面临着一个让我抓狂的问题! 我有一个函数,这个: void load_weapons3(t_env *e, char *name, int x, t_weapon *w) { char
我正在尝试使用 CUDA 中的最小值、最大值、总和和平均值实现并行归约。 这是我目前的主要代码片段。 int main() { const auto count = 8; const
我知道 double free 或 corruption 错误通常是对 big 3 的违规,但在这种情况下,我找不到违规发生的地方。我有一个复制构造函数、析构函数和赋值运算符,适用于任何处理指针的东西
GTK+ 中的“focus”和“focus-in(out)-event”信号有什么区别?哪个先发射?它们与键盘(TAB)和鼠标点击有什么关系。他们互相依赖吗? 我问这个是因为我想在顶层窗口中跟踪当前聚
*** glibc detected *** /home/ghoshs/workspace/Simulator/Debug/Simulator: double free or corruption (
#include #include #include #include using namespace std; #define MAX_WEIGHT 1000000 class Set {
我在服务器上有两个分支一个叫 R2 的分支和一个叫 DEV 的分支我无意中登录了错误的服务器,进入了存储库并执行了GIT pull 源开发但是存储库在 R2 上。所以我意识到我的错误然后尝试通过做一个
我有一个包含循环的大约 1000 个顶点和 3000 个边的有向图。 我试图从给定的顶点找到所有下游(出)路径。 使用以下 Gremlin 查询时 g.V(45712).repeat(out().si
使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息. 我见
我正在尝试创建一个 Zoom_image 函数,它使用离散傅里叶变换来缩放灰度图像。如果图像大小小于或等于 4*4 但大小增加,我包含的代码可以工作。它给出“双重释放或损坏(出)中止(核心转储)”错误
当我执行 popAll 函数时,出现以下错误: 双重释放或腐败(出)中止(核心转储) 我想我已经将错误来源缩小到了这个函数。 IntegerStack 是我制作的一个简单的 ADT,其中包含一个名为
我有网络开发背景,我正在尝试创建类似于 this technique 的东西适用于 iOS(使用 Cocoa/Obj C)。我在谷歌搜索资源时遇到了很多困难,因为 iOS 中的“视差”往往指的是 iO
我想实现一个 faceted search对于我的一个项目。我正在使用 PHP5、Mysql 和 Symfony 1.4。显然社区指向Apache Solr这似乎正是我想要完成的。 问题是该网站将在不
我知道有 questions floating around当您没有提供明确的分支名称时,关于来自特定分支的 git pull,但是我想知道即使用户确实指定了不同的分支,是否也可以强制 pull 分支
我正在尝试将我的更改推送到 NAS 上的存储库。它以我无法理解的方式失败。 documentation声明默认情况下 push 仅适用于快进更新。很公平。所以我做了一个 git pull(我的 Rem
我刚开始使用 Oracle 的 Coherence 缓存,我注意到这一点:如果我在缓存中放入一个 ConcurrentHashMap 对象,当我检索它时,我可以看到它被转换为一个普通的 HashMap
我尝试创建一个连接到数据库的线程,从那里获取一些数据并打印到控制台。问题是当该线程完成时抛出异常: 双重免费或腐败(出局)中止(核心转储) 我尝试使用 sqlite3 和 pthread,但这两个并不
我是一名优秀的程序员,十分优秀!