使用代理访问Google翻译接口

lib包见附件

public class Test {
	public static void main(String[] args) {
		// Set the HTTP referrer to your website address.
	    try {
	    	System.setProperty("http.proxyHost", "ip地址");
    		System.setProperty("http.proxyPort", "端口号");
	    	Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");

			String translatedText = Translate.execute("hello world", Language.ENGLISH, Language.CHINESE_SIMPLIFIED);

			System.out.println(translatedText);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


执行结果:

你好世界

你可能感兴趣的:(java,Google)