Reputation: 35
I´m currently working on an app and having my problems with uploading a JSONObject to my Iris CouchDb. But I can´t get it to work.
This is the code I´m using right now:
private class MyHttpPost extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... arg0)
{
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
HttpClient httpClient = new DefaultHttpClient(params);
HttpPost httpPost = new HttpPost("https://dbname.iriscouch.com/dbname");
try {
// Add your data
JSONObject jsonDoc = new JSONObject();
try {
jsonDoc.put("name", "test");
jsonDoc.put("autor", "test author");
jsonDoc.put("rundgangnr", "1");
jsonDoc.put("latitude", 58.0);
jsonDoc.put("longitude", 7.88);
} catch (JSONException e) {
e.printStackTrace();
} // end try
String body = jsonDoc.toString();
StringEntity entity = new StringEntity(body, "utf-8");
httpPost.setEntity(entity);
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
InputStream result = httpEntity.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
}
return true;
}
}
In onCreate I do this to execute the function:
new MyHttpPost().execute();
When I run the app, there are no errors but nothing gets uploaded. So there isn´t any change in the database.
Am I using the wrong URL to upload it on Iris or is there something wrong with the code? I´m new to Android development and really would appreciate your help as I have been struggling with this for days now.
Upvotes: 1
Views: 69
Reputation: 1836
Perhaps you need to use https://accountname.iriscouch.com/dbname
rather than https://dbname.iriscouch.com/dbname
.
Also, if the request throws an IOException, your app will be silently swallowing the error so you might not be seeing it.
Upvotes: 0