Note that there are some explanatory texts on larger screens.

plurals
  1. POCloudant/CouchDB Permissions on Key/Pass not working
    text
    copied!<p>I am having a problem getting information from Cloudant.com using a key/pass with read permissions (or all permissions). I was receiving a 500 error any way I would setup this user. However, currently everything is working fine, but I have left myself open for hacking, as I have to have my database open to be read by everyone. And we all know that can be a problem. I was wondering if anyone has any insight as to why this problem happens. BTW, I have tried it in both Android and iOS applications. This current question is using examples from an Android app.</p> <p>Here is the criteria from my singleton Utopia:</p> <pre><code>private static String _remote_db_protocal = "https"; private static String _remote_db_key = "mykey"; private static String _remote_db_pass = "mypass"; private static String _remote_db_account = "myaccount"; private static String _remote_db_dbname = "mydbname"; public static String REMOTE_JSON_DB_URL = _remote_db_protocal+"://"+ _remote_db_key+":"+_remote_db_pass+"@"+ _remote_db_account+".cloudant.com/"+_remote_db_dbname; </code></pre> <p>Here is the information I am sending to get a URL String response:</p> <pre><code> private static String dbBaseURL = Utopia.REMOTE_JSON_DB_URL; .... String dbQueryURL = "/_design/app/_view/toys"; URL finalURL; try { finalURL = new URL(dbBaseURL + dbQueryURL); Log.i(TAG, "Getting URL: "+finalURL.toString()); response = WebStuff.getURLStringResponse(finalURL); .... </code></pre> <p>And lastly, here is my getURLStringResponse() function:</p> <pre><code>/* * Get information back from a URL */ public static String getURLStringResponse(URL url) { String response = ""; try { URLConnection conn = url.openConnection(); BufferedInputStream bin = new BufferedInputStream(conn.getInputStream()); byte[] contentBytes = new byte[1024]; int bytesRead = 0; StringBuffer responseBuffer = new StringBuffer(); while ((bytesRead = bin.read(contentBytes)) != -1) { response = new String(contentBytes, 0, bytesRead); responseBuffer.append(response); } return responseBuffer.toString(); } catch (Exception e) { // TODO: handle exception Log.e(TAG, "getURLStringResponse Error as Follows"); Log.e(TAG, e.toString()); } return response; } </code></pre> <p>So with all of the above, I hope someone can answer the problem. I must also note, that I am to take my exact URL from the query that gets spit out in the log somewhere, or just recreate it from the REMOTE_JSON_DB_URL variable and values of what i'm looking for, and past that into the browser, everything worked fine (yes, being logged off of my account). </p> <p>EDIT: Correction, when I paste it into a browser, it asks for my login credentials and using the key/pass makes it work. I was asked by a Cloudant developer to pose this question to StackOverflow because they were unsure of what was happening (they also had my whole app with key/pass credentials and all). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload