1
我有一個簡單的程序,使用'apache http客戶端(4.5.2版本)'從一個URL獲取數據的問題。Apache客戶端java程序錯誤
請找到的代碼和下面的錯誤:
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>
能否請你幫忙嗎?