gpt4 book ai didi

java - HTTP请求在eclipse中可以工作,但在编译的JAR包中失败

转载 作者:太空宇宙 更新时间:2023-11-04 07:47:02 24 4
gpt4 key购买 nike

我正在使用 Apache HTTPclient 4 将 SPARQL 查询发送到远程存储库。虽然程序相同,但我的 JAR 包得到的响应是 HTTP 406,错误消息是“找不到可接受的文件格式”。在 Eclipse 中,我的查询成功收到 HTTP 200 响应和所需的结果。

什么可能导致具有相同代码的两个环境运行不同?

Eclipse 消息:(HTTP 200)

19:32:23.584 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - HttpConnectionManager.getConnection:  config = HostConfiguration[host=http://asimov.ludat.lth.se], timeout = 0
19:32:23.585 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Allocating new connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:32:23.585 [main] DEBUG o.a.c.httpclient.HttpConnection - Open connection to asimov.ludat.lth.se:80
19:32:23.589 [main] DEBUG httpclient.wire.header - >> "POST /openrdf-sesame/repositories/KnowRob HTTP/1.1[\r][\n]"
19:32:23.590 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Adding Host request header
19:32:23.593 [main] DEBUG httpclient.wire.header - >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
19:32:23.594 [main] DEBUG httpclient.wire.header - >> "Accept: application/x-binary-rdf-results-table[\r][\n]"
19:32:23.594 [main] DEBUG httpclient.wire.header - >> "Accept: application/sparql-results+xml;q=0.8[\r][\n]"
19:32:23.595 [main] DEBUG httpclient.wire.header - >> "Accept: application/xml;q=0.8[\r][\n]"
19:32:23.596 [main] DEBUG httpclient.wire.header - >> "Accept: text/tab-separated-values;q=0.8[\r][\n]"
19:32:23.596 [main] DEBUG httpclient.wire.header - >> "Accept: text/csv;q=0.8[\r][\n]"
19:32:23.597 [main] DEBUG httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
19:32:23.597 [main] DEBUG httpclient.wire.header - >> "Host: asimov.ludat.lth.se[\r][\n]"
19:32:23.598 [main] DEBUG httpclient.wire.header - >> "Content-Length: 836[\r][\n]"
19:32:23.598 [main] DEBUG httpclient.wire.header - >> "[\r][\n]"
19:32:23.599 [main] DEBUG httpclient.wire.content - >> "quer[...]rue"
19:32:23.600 [main] DEBUG o.a.c.h.m.EntityEnclosingMethod - Request body sent
19:32:24.304 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
19:32:24.304 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
19:32:24.305 [main] DEBUG httpclient.wire.header - << "Server: Apache-Coyote/1.1[\r][\n]"
19:32:24.305 [main] DEBUG httpclient.wire.header - << "Vary: Accept[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Disposition: attachment; filename=query-result.brt[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Type: application/x-binary-rdf-results-table;charset=ISO-8859-1[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Language: en-US[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "Transfer-Encoding: chunked[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "Date: Thu, 28 Feb 2013 18:28:24 GMT[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "[\r][\n]"
19:32:24.308 [main] DEBUG org.openrdf.http.client.HTTPClient - reponse MIME type is application/x-binary-rdf-results-table

JAR 消息:(HTTP 406)

19:15:35.178 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - HttpConnectionManager.getConnection:  config = HostConfiguration[host=http://asimov.ludat.lth.se], timeout = 0
19:15:35.179 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Allocating new connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:15:35.179 [main] DEBUG o.a.c.httpclient.HttpConnection - Open connection to asimov.ludat.lth.se:80
19:15:35.183 [main] DEBUG httpclient.wire.header - >> "POST /openrdf-sesame/repositories/KnowRob HTTP/1.1[\r][\n]"
19:15:35.184 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Adding Host request header
19:15:35.187 [main] DEBUG httpclient.wire.header - >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
19:15:35.188 [main] DEBUG httpclient.wire.header - >> "Accept: text/tab-separated-values;q=0.8[\r][\n]"
19:15:35.188 [main] DEBUG httpclient.wire.header - >> "Accept: text/csv;q=0.8[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "Host: asimov.ludat.lth.se[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "Content-Length: 836[\r][\n]"
19:15:35.190 [main] DEBUG httpclient.wire.header - >> "[\r][\n]"
19:15:35.191 [main] DEBUG httpclient.wire.content - >> "query[...]er=true"
19:15:35.191 [main] DEBUG o.a.c.h.m.EntityEnclosingMethod - Request body sent
19:15:35.717 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 406 Not Acceptable[\r][\n]"
19:15:35.717 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 406 Not Acceptable[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Server: Apache-Coyote/1.1[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Vary: Accept[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Content-Type: text/plain;charset=UTF-8[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Content-Language: en-US[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Content-Length: 32[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Date: Thu, 28 Feb 2013 18:11:35 GMT[\r][\n]"
19:15:35.720 [main] DEBUG httpclient.wire.header - << "[\r][\n]"
19:15:35.720 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Buffering response body
19:15:35.720 [main] DEBUG httpclient.wire.content - << "No acceptable file format found."
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Resorting to protocol version default close connection policy
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Should NOT close connection, using HTTP/1.1
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpConnection - Releasing connection back to connection manager.
19:15:35.721 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Freeing connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:15:35.722 [main] DEBUG o.a.c.h.util.IdleConnectionHandler - Adding connection at: 1362075335721
19:15:35.722 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Notifying no-one, there are no waiting threads
19:15:35.722 [main] WARN org.openrdf.http.client.HTTPClient - Server reports problem: No acceptable file format found.

最佳答案

在第一种情况下,您的应用程序/环境将 header 发送为

19:32:23.594 [main] DEBUG httpclient.wire.header - >> 
"Accept: application/x-binary-rdf-results-table[\r][\n]"

但在第二种情况下缺少此内容,因此您的第二个环境无法接受 'application/x-binary-rdf-results-table' 类型的响应。您在哪里运行第二个查询? jar部署在哪里?您可能需要将此编码/类型添加到您的应用服务器。

我不太清楚您在哪里使用它,但好的起点是了解为什么在第二种情况下缺少“Accept:application/x-binary-rdf-results-table”。

关于java - HTTP请求在eclipse中可以工作,但在编译的JAR包中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15143043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com