[英]Error with apache http client java program
我有一个简单程序的问题,使用'apache http client(4.5.2 version)'从url获取数据。
请在下面找到代码和错误:
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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.