【发布时间】:2015-02-19 22:31:42
【问题描述】:
我在使用 Apache HttpClient 为 TextGetTargetedSentiment 调用 AlchemyAPI 时收到 org.apache.http.client.ClientProtocolException:
org.apache.http.ProtocolException: 服务器未能响应有效的 HTTP 响应
下面是代码sn-p。
URI uri = new URIBuilder()
.setScheme("http")
.setHost("access.alchemyapi.com/calls/text/TextGetTargetedSentiment")
.setParameter("apikey", <api-key>)
.setParameter("outputMode", "json")
.setParameter("showSourceText", "0")
.setParameter("target", <target>)
.setParameter("text", <news article>)
.build();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(uri);
// add header
post.setHeader("User-Agent", <user agent>);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = client.execute(post);
感谢您的帮助。
【问题讨论】:
-
如果有异常消息或堆栈跟踪,您应该包含它(至少在异常源行中)
-
@fejese 我只能看到原因 -
org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
标签: java apache apache-httpclient-4.x alchemyapi