簡體   English   中英

通過屬性URL傳遞服務器URL在Apache HTTP客戶端中不起作用

[英]Passing server URL through properties file not working in apache http client

我正在嘗試通過屬性文件讀取url並傳遞到apache http post構造函數中。當我這樣做時,我遇到404錯誤,並且在對其進行硬編碼時,它工作正常。我不知道兩者之間有什么區別方法。 從屬性文件讀取后,我正在控制台上打印變量,它顯示的是確切的網址,但是當我在http apache客戶端中傳遞相同的字符串變量時,我卻收到了“ 404 not found”的消息。

閱讀網址:

    requestURL = MWTConfiguration.getInstance().getValue("NPCI_AUTH_URL");
                System.out.println("Request URL :"+requestURL);
                objAuthRequest.setPid(objFITransXTRequest.getPid());
                objAuthRequest.setRbd(""); 
 authResponse =objMWTHttpClient.execute(strRequestJson, requestURL);  

客戶代碼:

public String execute(String requestData, String strURL) throws ParseException, Exception {
        String strResponse = "";
        StringBuffer objSBuffer = new StringBuffer();
        try {
            HttpClient httpClient = HttpClientBuilder.create().build();
            System.out.println("URLLLL : :"+strURL);
            HttpPost reqFundTransf = new HttpPost(strURL);
            StringEntity params = new StringEntity(requestData);
            reqFundTransf.addHeader("content-type", "application/json");
            reqFundTransf.setEntity(params);
            HttpResponse objResponse = httpClient.execute(reqFundTransf);
            HttpEntity objRespEntity = objResponse.getEntity();
            BufferedReader objBReader = new BufferedReader(new InputStreamReader(objRespEntity.getContent()));

            while ((strResponse = objBReader.readLine()) != null) {
                objSBuffer.append(strResponse);
            }

        } catch (Exception e) {
            throw new Exception(e);
        }
        return objSBuffer.toString();

控制台視圖:

URLLLL : :http://223.30.66.28:8080/AEPSNPCI/rest/aepsauth/authentication
2017-03-14 16:08:27 DEBUG RequestAddCookies:122 - CookieSpec selected: best-match
2017-03-14 16:08:27 DEBUG RequestAuthCache:75 - Auth cache not set in the context
2017-03-14 16:08:27 DEBUG PoolingHttpClientConnectionManager:219 - Connection request: [route: {}->http://223.30.66.28:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2017-03-14 16:08:27 DEBUG PoolingHttpClientConnectionManager:250 - Connection leased: [id: 0][route: {}->http://223.30.66.28:8080][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
2017-03-14 16:08:27 DEBUG MainClientExec:217 - Opening connection {}->http://223.30.66.28:8080
2017-03-14 16:08:27 DEBUG HttpClientConnectionOperator:120 - Connecting to /223.30.66.28:8080
2017-03-14 16:08:27 DEBUG HttpClientConnectionOperator:127 - Connection established 10.9.31.135:44782<->223.30.66.28:8080
2017-03-14 16:08:27 DEBUG MainClientExec:238 - Executing request POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1
2017-03-14 16:08:27 DEBUG MainClientExec:243 - Target auth state: UNCHALLENGED
2017-03-14 16:08:27 DEBUG MainClientExec:249 - Proxy auth state: UNCHALLENGED
2017-03-14 16:08:27 DEBUG headers:124 - http-outgoing-0 >> POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> content-type: application/json
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Content-Length: 729
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Host: 223.30.66.28:8080
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Connection: Keep-Alive
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.4 (java 1.5)
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "content-type: application/json[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Content-Length: 729[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Host: 223.30.66.28:8080[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.4 (java 1.5)[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:86 - http-outgoing-0 >> "{"modality":{"fp":true,"otp":false},"uidNumber":"496640436689","rrn":"707316193975","pid":"YUVIL7CKWbBjFV+UCZBKGMnLJeHSNJjrZ6r+0kyfMZl0VEKNeIHyeaXFPLsYXyxJ9qISBTPmN/4qrS82AT781Q\u003d\u003d","rbd":"","hmac":"XuVPiZ9kLxHSAzxzyFqu+eY18F1bQVqOzjbGF7Pc21L2ohIFM+Y3/iqtLzYBPvzV","ci":"20170227","sKey":"lrq66RF9C0H00tFVA3MjRRui0NFyM/1BlYxfJkzHFZhrWaLt1xpUd7M1z1skeXqJwNmB7Ygcyht22Tqr701eHSiZTKWl6N4gJLDr4EZjDB+OYqDTg28qSiHC3/TDvASr9m+F0ymKZhAdw7aASf+ZCxpkdjBOI/FzaIlTo67r9azYeVKPd/53bnpOvboxUdpt0coI8ElheTArcE5xQVDVC3Y5iJYkARjVgRonrjWSLlb0D9WzZ2Aolq2vnwo7nnglb0uqiqanUUrStqK//MNcVq5R5acu5hZv83XZNH0m/4v1+Ku3zQp0Kuc6nRNkE0M6f+LKZJ8JlkeSnIwoubFA1Q\u003d\u003d","metaData":{"udc":"AX20123","pip":"10.230.23.24","lot":"P","lov":"244221"}}"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 << "HTTP/1.1 404 Not Found[\r][\n]" 

使用“修剪功能”,在字符串的結尾或開頭可能會有一個空格。

HttpPost reqFundTransf = new HttpPost(strURL.trim());

嘗試將其更改為反斜杠。

在屬性文件中提到的網址中,您可能缺少正斜杠的轉義字符。

嘗試在正斜杠前使用'\\ /'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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