Note that there are some explanatory texts on larger screens.

plurals
  1. POExec'ing CURL from Java - whats the proper way?
    primarykey
    data
    text
    <p>I am executing curl via the following code:</p> <pre><code> // execute process Process pr = null; Runtime run = Runtime.getRuntime(); try { pr = run.exec(cmdline.split(" ")); A ret = f.f(pr); pr.waitFor(); return ret; } catch (Exception ex) { throw new RuntimeException("Executing " + cmdline, ex); } finally { try { // close all those bloody streams pr.getErrorStream().close(); pr.getInputStream().close(); pr.getOutputStream().close(); } catch (IOException ex) { Log.get().exception(Log.Level.Error, "Closing stream: ", ex); } } </code></pre> <p>However, when I add the following into the exec string:</p> <p>I am building the curl string as I go, before I pass it to the method seen above:</p> <pre><code> if (userAgent.contains(" ")) { userAgent = " --user-agent '" + Exec.escapeShellString(userAgent) + "' "; } </code></pre> <p>With the extra single quotes I get this:</p> <pre><code>113.30.31.137 - - [03/Feb/2012:05:26:39 +0000] "GET / HTTP/1.1" 200 6781 "-" "'Mozilla/5.0(iPad;U;CPUOS3_2_1)'" </code></pre> <p>Without the single quotes, I get this:</p> <pre><code>107.21.172.36 - - [03/Feb/2012:05:33:38 +0000] "GET / HTTP/1.1" 200 6781 "-" "'Mozilla/5.0(iPad;U;CPUOS3_2_1)" </code></pre> <p>There is a leading single quote, but not a finishing one. I believe that there should be no single quotes.. anyhow, there is magic somewhere between java and curl...</p> <p>All I would like to do is pass a string like this: Opera/9.25 (Windows NT 6.0; U; en)</p> <p>and expect this:</p> <pre><code>107.21.172.36 - - [03/Feb/2012:05:33:38 +0000] "GET / HTTP/1.1" 200 6781 "-" "Opera/9.25 (Windows NT 6.0; U; en)" </code></pre> <p>Edit:</p> <p>The reason I am using curl is because curl seems to be the only option that retrieves the content on any response other than 200.301 or 302.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload