apache http客户端java程序出错
使用“ApacheHTTP客户端(4.5.2版本)”从url获取数据的简单程序有一个问题 请在下面查找代码和错误:apache http客户端java程序出错,java,httpclient,apache-commons-httpclient,Java,Httpclient,Apache Commons Httpclient,使用“ApacheHTTP客户端(4.5.2版本)”从url获取数据的简单程序有一个问题 请在下面查找代码和错误: public static void main(String[] args) throws Exception { String username = "user"; String password = "pwd"; String urlString = "xyz.com?a=b&c=d"; org.apac
public static void main(String[] args) throws Exception {
String username = "user";
String password = "pwd";
String urlString = "xyz.com?a=b&c=d";
org.apache.http.client.HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(urlString);
org.apache.http.auth.UsernamePasswordCredentials creds = new org.apache.http.auth.UsernamePasswordCredentials(
username, password);
request.addHeader(new BasicScheme().authenticate(creds, request));
HttpResponse response = client.execute(request);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
result.append(line);
}
}
错误:
<Error><Code>InvalidArgument</Code><Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message>
您能提供帮助吗?我没有遇到上面的错误,但是在给定代码开头添加了“http://”之后,我能够毫无错误地运行此代码示例
String urlString = "xyz.com?a=b&c=d";
我没有遇到上面的错误,但是在给定代码开头添加了“http://”之后,我能够毫无错误地运行此代码示例
String urlString = "xyz.com?a=b&c=d";