k***r 发帖数: 4260 | 1 哪位大峡知道如何在HttpURLConnection里面使用proxy?
我找到的很多sample code 都是用 system property (见下),
但是都不work。里面随便设成bogus ip:port也能拿到page,
说明没有通过proxy出去。
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", new
Integer(proxyPort).toString());
有了解的请知会一声,如果找到类似sample code,这个不work :( |
g*****g 发帖数: 34805 | 2 这个东西我用过,就是这么用没错。你试试看在hosts文件里
把你要去的ip禁掉,再试试看。
【在 k***r 的大作中提到】 : 哪位大峡知道如何在HttpURLConnection里面使用proxy? : 我找到的很多sample code 都是用 system property (见下), : 但是都不work。里面随便设成bogus ip:port也能拿到page, : 说明没有通过proxy出去。 : System.setProperty("https.proxyHost", proxyHost); : System.setProperty("https.proxyPort", new : Integer(proxyPort).toString()); : 有了解的请知会一声,如果找到类似sample code,这个不work :(
|
k***r 发帖数: 4260 | 3 It falls back to no proxy if proxy server doesn't connect!
But this isn't the behavior I want. Why not leave the logic
to the application. Java tries to be smart where it really
shouldn't :(
【在 g*****g 的大作中提到】 : 这个东西我用过,就是这么用没错。你试试看在hosts文件里 : 把你要去的ip禁掉,再试试看。
|
m******t 发帖数: 2416 | 4
How did you make sure that it actually tried the proxy first?
Take a look at httpclient. It has more sophisticated
proxy handling code than the jdk code.
【在 k***r 的大作中提到】 : 哪位大峡知道如何在HttpURLConnection里面使用proxy? : 我找到的很多sample code 都是用 system property (见下), : 但是都不work。里面随便设成bogus ip:port也能拿到page, : 说明没有通过proxy出去。 : System.setProperty("https.proxyHost", proxyHost); : System.setProperty("https.proxyPort", new : Integer(proxyPort).toString()); : 有了解的请知会一声,如果找到类似sample code,这个不work :(
|
k***r 发帖数: 4260 | 5 i'm not so sure. but from the time it uses to connect,
it seems that it didn't fail then try the proxy.
Yeah, I may just use the httpclient lib. I didn't want
to bother with an additional jar - didn't know jvm handles
proxies like this.
【在 m******t 的大作中提到】 : : How did you make sure that it actually tried the proxy first? : Take a look at httpclient. It has more sophisticated : proxy handling code than the jdk code.
|
m******t 发帖数: 2416 | 6
The reason I suspect that it's not even trying the proxy
is that it should definitely blow up if the proxy address
isn't correct, instead of falling back _silently_.
【在 k***r 的大作中提到】 : i'm not so sure. but from the time it uses to connect, : it seems that it didn't fail then try the proxy. : Yeah, I may just use the httpclient lib. I didn't want : to bother with an additional jar - didn't know jvm handles : proxies like this.
|
k***r 发帖数: 4260 | 7 I've seen bugs on sun.com discussing the fallback.
【在 m******t 的大作中提到】 : : The reason I suspect that it's not even trying the proxy : is that it should definitely blow up if the proxy address : isn't correct, instead of falling back _silently_.
|