-- 作者:xpg0312
-- 发布时间:2/5/2007 10:07:00 AM
-- java application 中如何访问网络
小弟在课题的研究中需要到国外的网站上去检索一些信息,但是那个网站需要用户名和密码,我已经在那里注册,可以在应用程序中怎样才能建立到该服务器的连接呢。 我要连的是UMLSKS。用示例程序试了一下,但是总是返回异常,原因是拒绝连接,非授权ip。程序代码如下: import java.io.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.rmi.*; import gov.nih.nlm.kss.util.*; import gov.nih.nlm.kss.api.*; import gov.nih.nlm.kss.models.meta.concept.*; import gov.nih.nlm.kss.models.meta.assocExp.*; import gov.nih.nlm.kss.models.meta.relation.*; import gov.nih.nlm.kss.models.meta.context.*; import gov.nih.nlm.kss.models.meta.cooccurrence.*; import gov.nih.nlm.kss.models.meta.attribute.*; public class UmlsTest extends Authenticator{ public static void main(String args[]){ UmlsTest ut= new UmlsTest(); try { String name = "//umlsks.nlm.nih.gov/KSSRetriever"; KSSRetrieverV5_0 retriever = (KSSRetrieverV5_0)Naming.lookup(name); char[] result = retriever.getConceptName("2001", "C0001175", null, "ENG"); String conceptName = new String(result); String protocal=ut.getRequestingProtocol(); System.out.println(protocal); System.out.println("Concept Name in XML: " + conceptName); } catch (RemoteException ex) { // handle remote exception System.out.println(ex); } catch (NotBoundException ex) { // handle fact that the server is not bound to the given name System.out.println("not bound in the remote"+ ex.getMessage()); } catch (MalformedURLException ex) { // handle fact that the name was not a properly formatted URL System.out.println(ex); }catch(DatabaseException e){ System.out.println("cann't open database "+e); } } } 返回的结果如下: cann't open database gov.nih.nlm.kss.util.DatabaseException: Unable to validate user information; Connection refused; invalid client IP address 我觉得应该是没有登陆的原因,如果我在网站正常登陆,用web是可以进行查询等操作的。希望高手给予指点。我的邮箱:xpg0312@163.com
|