有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Jersey客户端将覆盖ROBOTS响应

我使用下面的代码从服务器获取响应。当我使用POSTMAN时,它给出了一个不同的清晰响应,当我使用jersey客户端的java代码时,它给出了robots响应,假设我的请求是恶意的。我使用的是jersey 1.9版本

问:如何克服这个机器人

 ObjectMapper mapper = new ObjectMapper();Client CLIENT = Client.create();
    CLIENT.addFilter(new LoggingFilter(System.out));
    WebResource webResource = null;
    webResource = CLIENT.resource(url);
    ClientResponse response = null;
    response = webResource
                                .header("Cache-Control", "no-cache")
                                .header("Cookies", false)
                                .accept(MediaType.APPLICATION_JSON)
                        .get(ClientResponse.class)
                ;

下面是来自邮递员的标题信息。在POSTMAN中,会话id设置为true

   Accept-Ranges →bytes
    Age →1
    Cache-Control →public, max-age=0, must-revalidate, no-transform
    Content-Encoding →gzip
    Content-Length →5533
    Content-Security-Policy →default-src 'self' https://www.xxxx.xxxx https://*.cwp.xxxx.xxxx 
    Content-Type →application/json
    Content-language →en-US
    Pragma →no-cache
    Server →ngccc
    Set-Cookie →SECSESSID=2aprjner5fomn8vrk4sfhbn464; expires=Tue, 23-Jan-2018 18:35:09 GMT; Max-Age=3600; path=/; secure; HttpOnly
    Set-Cookie →SECSESSID=2aprjner5fomn8vrk4sfhbn464; expires=Tue, 23-Jan-2018 18:35:09 GMT; Max-Age=3600; path=/; secure; httponly
    Set-Cookie →SECSESSID_2=asdasdasdxxsdsdxx; expires=Tue, 23-Jan-2018 17:59:09 GMT; Max-Age=1440; path=/; secure; httponly
    Set-Cookie →incap_ses_899_110069=+lYvxV259l1WSI2o+LzxVsA==; path=/; Domain=.www.xxxx.xxxx
    Strict-Transport-Security →max-age=31536000
    Vary →Accept-Encoding
    Via →1.1 varnish-v4, HTTPS/1.1 localhost.localdomain
    X-CDN →Incapsula
    X-Content-Type-Options →nosniff
    X-Frame-Options →SAMEORIGIN
    X-UA-Compatible →IE=edge
    X-Varnish →436830982
    X-XSS-Protection →1; mode=block

以下是代码的响应:

<html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=2977">
</script>
<script>
(function() { 
var z="";var b="7472797B766172207868723B7661";for (var i=0;i<b.length;i+=2){z=z+parseInt(b.substring(i, i+2), 16)+",";}z = z.substring(0,z.length-1); eval(eval('String.fromCharCode('+z+')'));})();
</script></head>
<body>
<iframe style="display:none;visibility:hidden;" 
</body></html>

以下是邮递员的回应:

{
    "query": {
        "offset": 0,
        "count": 20,
        "total": 379
    }
}

共 (1) 个答案

  1. # 1 楼答案

    通过在其中添加与SSL连接相关的代码,解决了此问题。因此,它识别并验证了该请求,并以有效响应进行了响应