在eclipse中使用subclipse,發現無法訪問到目標subversion服務器,總是報服務器無法連接。我連的subversion服務器采用apache以http的形式發布,用瀏覽器直接打開URL可以訪問。由于公司網絡環境是要求使用http proxy的,因此第一個想法就是eclipse沒有使用http proxy因此無法連接外網。
簡單驗證了一下,用eclipse的software update工具,試圖訪問外部站點獲取更新信息,報錯無法訪問。問題確認,找了一下eclipse的配置,window -》prererences-》General -》Network Connections 下,有網絡連接的設置,默認是"Direct connection to the Internet"/直接訪問因特網。
這樣當然出不去了,隨即修改為公司目前使用的http proxy,測試了一下software update可以正常工作。中間有個小插曲,http proxy設置中,proxy.***.com前千萬不要加"http://",否則無法使用,因為這個原因浪費了不少時間。但是再試subclipse連接subversion服務器時,還是同樣的報錯,無法連接到服務器。暈......
google了一下沒有找到直接答案,花了點時間最后找到了subversion的FAQ,發現有下面這么一段:
http://subversion.tigris.org/faq.html#proxy
What if I'm behind a proxy?
The Subversion client can go through a proxy, if you configure it to do so. First, edit your "servers" configuration file to indicate which proxy to use. The files location depends on your operating system. On Linux or Unix it is located in the directory "~/.subversion". On Windows it is in "%APPDATA%\Subversion". (Try "echo %APPDATA%", note this is a hidden directory.)
There are comments in the file explaining what to do. If you don't have that file, get the latest Subversion client and run any command; this will cause the configuration directory and template files to be created.
言下之意,subversion客戶端訪問外網時,http proxy的設置是通過“%APPDATA%\Subversion\servers”這里來設置的,eclipse的設置對它無效!
不說二話,直接找到“%APPDATA%\Subversion\servers”文件,因為我這里情況簡單,直接修改最下面的[global]設置,打開注釋并修改為當前環境下的http-proxy
http-proxy-host = iproxy-sh.****.se
http-proxy-port = 8080
再試就ok了,成功連接到subversion服務器。
PS: 中間還看到,subversion使用到一些特殊的http head,比如PROPFIND, REPORT, MERGE, MKACTIVITY, CHECKOUT。對于某些無法支持這些header的http proxy,需要使用其他的方法,比如使用https。由于暫時沒有遇到這個問題,不花時間研究了。
update: 發現在linux上,通過subversion來訪問網絡,也是可以設置代理服務器的,方法類似,不過需要修改的文件時當前用戶的home目錄下, .subversion/servers文件,方式同上。