Curl incosistent behaviour – CLI vs Java process

Trying to grab HTML for ttps://www.target.com.au/ with cUrl

This works ok via command-line:

xxx@VirtualBox:~/workspace/$ /usr/bin/curl -L -v -k -i -H "Accept: text/html" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" --max-time 10 https://www.target.com.au/ > target
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 23.0.111.198...
* TCP_NODELAY set
* Connected to www.target.com.au (23.0.111.198) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
.....

This always fail via Java:

    InputStream is = null;
    try {
        String command = "/usr/bin/curl -L -v -k -i -H \"Accept: text/html\" -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36\" --max-time 10 " + url;
        System.out.println(command);
        Process process = Runtime.getRuntime().exec(command);
        is = process.getInputStream();
        String body = IOUtils.toString(is, StandardCharsets.UTF_8);
        return body;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
    }

OUTPUT:

/usr/bin/curl -L -v -k -i -H “Accept: text/html” -H “User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36” –max-time 10 https://www.target.com.au/

HTTP/2 403 server: AkamaiGHost mime-version: 1.0 content-type: text/html content-length: 270 expires: Fri, 05 Jul 2019 00:17:29 GMT date: Fri, 05 Jul 2019 00:17:29 GMT set-cookie: akavpau_prod_maintenance_vp=1562286149~id=979d0dae2676e513c633ce4f23c24ce0; Path=/ set-cookie: bm_sz=11D295C99ED7B362AFBB7A506F5BBD77~YAAQXrEHyloISrBrAQAAjzx+vwQpr3VkKRJiHodkXRN0RKsY9mAJuPB0g9bwOPcKkRcYltVyQ/K8f5vygv9S80T59R2NDJoF1Ei/2nfEUUicPAdkhSpnWYdXZiBSv0TTqbXZeEauEzVff4OjwhhvL6sGI43knNUZbliMNZecBDuoXjDUvZD/o/JFAtxWR3lRI+t3; Domain=.target.com.au; Path=/; Expires=Fri, 05 Jul 2019 04:17:29 GMT; Max-Age=14400; HttpOnly set-cookie: _abck=EA0253F20FADD24AE9333A50CD207788~-1~YAAQXrEHylsISrBrAQAAjzx+vwJv1VRMgxWDzHyBa1150prHaQO88ZGzl8kuNGzw3XRjLqOJaOMbT9mm5eWjT1pzMZq5WgyzPZM1+pc3n0UDCkVSZCZzon4/EXAkpbMNMeQfpHaurjCxf17U7javVptDE44op+nti7YNmdKUemKT/wMAL3RbWuPKwMRsduKFp1qyOQvK7tYOemfHd21YEFz/f1dGM+4SNqxRECJD4U+ErNQYJd93q3Mfca6QgOz1sDhvSGUNghKBCovxdjwLjaW77iZfZMI5owWID57L5Q==~-1~-1~-1; Domain=.target.com.au; Path=/; Expires=Sat, 04 Jul 2020 00:17:29 GMT; Max-Age=31536000; Secure

Access Denied

Access Denied

You don’t have permission to access “http://www.target.com.au/” on this server.

Reference #18.5eb107ca.1562285849.864a545

cUrl location is the same in both cases (Ubuntu), same machine.

xxx@VirtualBox:~/workspace/$ curl --version
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

Leave a Comment

tech