java - 通过属性文件传递服务器 URL 在 apache http 客户端中不起作用

标签 java http-status-code-404 apache-httpclient-4.x properties-file

我正在尝试通过属性文件读取 url 并传递到 apache http post 构造函数。当我这样做时,我收到 404 错误,当对其进行硬编码时,它工作正常。我不知道是什么两种方法之间的差异。从属性文件读取后,我在控制台上打印变量,它显示了确切的 url,但是当我在 http apache 客户端中传递相同的字符串变量时,我收到“404 未找到”。任何人都可以指导我吗?谢谢

阅读网址:

    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();

控制台 View :

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());

关于java - 通过属性文件传递服务器 URL 在 apache http 客户端中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42784007/

相关文章:

java - 触摸监听器和改变 parent

Java `final` 类和模拟

java - 将 DXL 与 eclipse/notes 相关联并开始处理

javascript - 已发布的 css/js 文件在 azure 门户中返回 404

apache - CentOS HTTPD SSL 404 错误

java - 使用 Apache HTTPClient 时无法释放连接

java - HTTP请求在eclipse中可以工作,但在编译的JAR包中失败

java - 使用 jdk8 Conscrypt 为 http2 启用 ALPN

java - JUnit/ Selenium : Splitting my class to use the Page Object Model

php - 在 Kohana 中,你能触发 404 错误吗?