現在、アプリに取り組んでおり、JSONObject を Iris CouchDb にアップロードする際に問題が発生しています。しかし、私はそれを機能させることができません。
これは私が今使っているコードです:
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;
}
}
onCreate では、これを実行して関数を実行します。
new MyHttpPost().execute();
アプリを実行すると、エラーはありませんが、何もアップロードされません。したがって、データベースに変更はありません。
Iris にアップロードするのに間違った URL を使用していますか、それともコードに何か問題がありますか? 私は Android 開発に不慣れで、これに何日も苦労しているので、本当に助けていただければ幸いです。