使用POST将数据从Android发送到AppEngine数据存储区 [英] Using POST to send data from Android to AppEngine Datastore

查看:58
本文介绍了使用POST将数据从Android发送到AppEngine数据存储区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一个简单的问题,但我只是想不出我该怎么做,我想我在这儿有点儿不足.我想将数据从Android应用程序发送到在Google App Engine上运行的应用程序.从那里必须将数据写入数据存储.我的数据大部分将以对象的形式出现,并且我正在使用Java.

Sorry if this is a simple question, but I just can't figure out what I'm supposed to do and I think I'm a bit out of my depth here. I want to send data from an Android Application to my application running on Google App Engine. From there the data must be written to the Datastore. My data will mostly be in the form of objects, and I am working in Java.

我遇到了以下问题:我想我了解Android方面必须发生的事情.我也了解doPost方法的工作原理以及应该做的事情.但是我的问题是,现在如何使用PersistenceManagerFactory将这些数据写入我的数据存储区或进行检索?即,如果我想在那里使用PersistenceManagerFactory,那么doPost中的代码将如何显示?

I think I understand what has to happen on the Android side. I also understand how the doPost method works and what it's supposed to do. But my problem is this, how can I now use PersistenceManagerFactory to write this data to my Datastore, or retrieve it? I.e., how would the code inside the doPost look, if I wanted to use PersistenceManagerFactory there?

从本质上讲,我的移动应用程序必须能够与带w.r.t的AppEngine应用程序执行相同的操作.数据检索/写入.

Essentially, my mobile application must be able to do the same as my AppEngine application w.r.t. data retrieval/writing.

还是我应该忘记这种方法而做一些不同的事情?

Or should I forget about this method and do something different?

任何朝着正确方向的指针将不胜感激!

Any pointer in the right direction will be greatly appreciated!

我已经开始实施Sam的解决方案,如下所示.但是,某些事情仍然不正确.这是我目前正在做的事情:

I have started implementing Sam's solution as shown below. However, something is still nor right. here is what I am currently doing:

在我的GAE应用程序的web.xml中映射我的servlet:

Mapping my servlet in web.xml of my GAE-app:

<servlet>
    <servlet-name>this_servlet</servlet-name>
<servlet-class>*app-details*.server.JsonNews</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>this_servlet</servlet-name>
    <url-pattern>/my_app/my_app_place</url-pattern>
</servlet-mapping>

doPost()方法的实现与Sam的实现相同.

The implementation of the doPost() Method is the same as Sam's.

在我的Android应用中:

In my Android-app:

DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
HttpPost postMethod=new HttpPost("http://my_application.appspot.com/my_app/my_app_place");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
nameValuePairs.add(new BasicNameValuePair("value1", "Value my user entered"));  
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
String response=hc.execute(postMethod,res);

但是,hc.execute方法失败,并向我提供以下消息:Internal Server Error

However, the hc.execute method fails, and provides me with the following message: Internal Server Error

这使我相信该错误一定是在服务器端,但是我不确定哪里或为什么会出错.我完全复制了Sam的代码,只更改了诸如新闻"之类的必要内容.

This leads me to believe that the error must be on the server side- but I am not sure where or why things are going wrong. I copied Sam's code exactly, only changing the necessary things like "News".

推荐答案

此问题解决了我的确切问题:

This question solves my exact problem:

how-to-send-a-json-object-over-request-withandroid

请参阅dmazzoni和primpop的答案.

See dmazzoni and primpop's answers.

这篇关于使用POST将数据从Android发送到AppEngine数据存储区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆