嘿我正在尝试在java
中运行命令:
String curlCommand=String.format("curl --max-time %d --socks5 %s -A \"%s\" -i %s",maxWait,proxy ,getAgent(), myurl);
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(curlCommand);
由于某些原因,执行此行会导致cookies
被拒绝。
然而,当我从终端运行curl程序时,我没有问题,一切正常,
如果我运行程序Java
Date: Tue, 03 Mar 2015 19:20:38 GMT
X-Li-Pop: prod-lva1
X-LI-UUID: 8C548z0TyBMwY002tCoAAA==
Set-Cookie: denial-reason-code=3,2,8; Max-Age=5
Set-Cookie: denial-client-ip=xxxxxxx; Max-Age=5
Content-Length: 1852
Content-Type: text/html
如果我使用curl
中的terminal
运行完全命令,则结果如下:
HTTP/1.1 200 OK
Server: Play
X-SSR-Engine-Init: <xxxxxxx>
X-FS-UUID: 0e69d33f4913c813b05f1aefb42a0000
X-Page-Speed: 1
Date: Tue, 03 Mar 2015 19:21:27 GMT
Content-Length: 31113
Content-Type: text/html; charset=utf-8
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Li-Fabric: prod-lva1
Strict-Transport-Security: max-age=0
Set-Cookie: JSESSIONID="ajax:4773794645302404176"; Path=/; Domain=<xxxxxx>; HTTPOnly
Set-Cookie: bcookie="v=2&da2801ec-e7e2-4b04-8244-401d6ac0e7c3"; domain=xxxxx; Path=/; Expires=Fri, 03-Mar-2017 06:58:59 GMT
Set-Cookie: bscookie="v=1&2015030319212713ed4940-eb5d-4860-8c30-2eec4819157aAQHMGWOb0Fiv_feTewpb6Rw3TGGAGQ_Q"; domain=<xxxxxx>; Path=/; Secure; Expires=Fri, 03-Mar-2017 06:58:59 GMT; HttpOnly
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store
Connection: keep-alive
X-Li-Pop: prod-lva1
X-LI-UUID: DmnTP0kTyBOwXxrvtCoAAA==
Set-Cookie: lidc="b=VB97:g=149:u=1:i=1425410487:t=1425496887:s=AQHAOhdkFxryw00Wo64LkfjsYb8Q1hqZ"; Expires=Wed, 04 Mar 2015 19:21:27 GMT; domain=<xxxxx>; Path=/
所以我的问题是为什么它应该有所不同,我在这里遗漏了什么?
答案 0 :(得分:0)
好吧,我终于解决了。
原因是Runtime runtime = Runtime.getRuntime();
不应该使用它。因为它只是弄乱了参数(尽管命令打印出来看起来很好,但它没有向操作系统发送正确的命令)而是我应该使用ProcessBuilder
class
。它就像一个魅力。