首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android中上传JSONObject到Iris CouchDb

在Android中上传JSONObject到Iris CouchDb
EN

Stack Overflow用户
提问于 2015-06-15 00:46:34
回答 1查看 66关注 0票数 1

我目前正在开发一款应用程序,在向我的Iris CouchDb上传JSONObject时遇到了问题。但是我不能让它工作。

这是我现在使用的代码:

代码语言:javascript
复制
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中,我这样做是为了执行函数:

代码语言:javascript
复制
new MyHttpPost().execute();

当我运行应用程序时,没有任何错误,但没有上传任何内容。所以在数据库中没有任何变化。

我是不是用了错误的URL上传到Iris上,还是代码有问题?我是Android开发的新手,真的很感谢你的帮助,因为我已经在这个问题上挣扎了几天。

EN

回答 1

Stack Overflow用户

发布于 2015-06-25 17:49:39

也许您需要使用https://accountname.iriscouch.com/dbname而不是https://dbname.iriscouch.com/dbname

此外,如果请求抛出一个IOException,你的应用程序将会默默地接受错误,所以你可能看不到它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30831979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档