There are obvious risks, but you could set up the HTTP server to permit access based on a given user's permissions so that you don't have to supply username and password. That works nicely in an Intranet.
Tim From: [email protected] [mailto:[email protected]] On Behalf Of Bharat kumar Sent: Thursday, March 17, 2011 7:52 AM To: General MarkLogic Developer Discussion Subject: [MarkLogic Dev General] Opening URL COnnection to Marklogic Hi, We have created a HTTP server(with port 8005) in Marklogic and we just wrote some sample xqy file(request.xqy) which will return plain XML. So if we are hitting the URL in browser its asking for username and password, once we give the details its giving the sample XML output. URL : http://localhost:8005/request.xqy Username : admin Password : admin. Output of request.xqy : <abc>hi</abc> So we are trying to open the same connection from Java using URLConnection but we are getting the 401 unauthorized error code. We are making sure that we are embedding the username and password. But still its giving error code. Here is the Java code whcih we have used. URL url = new URL("http://10.201.174.163:8005/request.xqy"); String userName = "admin"; String password= "admin"; String userPassword=userName + ":" +password; String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); System.out.println(encoding); URLConnection connection = url.openConnection(); String encoding = base64Encode(userPassword); connection.setRequestProperty("Authorization", "Basic " + encoding); BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); The same way is implemented in some other project in our account and its working fine. But we are not aware of the marklogic settings. Please help us and let us know whether we need to do any other settings from Marklogic side to allow accessing the marklogic application using HttpConnection by Java. Thanks in Advance. Regards, Bharat. K
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
