簡體   English   中英

apache http客戶端java程序出錯

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM