2016-07-19 67 views
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> 

能否請你幫忙嗎?

回答

0

我沒有遇到上述錯誤,但我可以添加後運行,並沒有錯誤此代碼示例中的「http://」給定

String urlString = "xyz.com?a=b&c=d"; 
的開始