[英]How to send data from Android mobile devices to the Google App Engine datastore?
I need to write an application that sends data to the Google App Engine from Android. 我需要编写一个从Android向Google App Engine发送数据的应用程序。 The data that I would like to send can be described by a typical database record. 我想发送的数据可以通过典型的数据库记录来描述。 Each record has some integers, strings, dates, etc. I would like to keep the connection details hidden/secured so that someone can't create false data in the datastore, if it it's not too involved. 每个记录都有一些整数,字符串,日期等。我希望隐藏/保护连接细节,以便有人不能在数据存储区中创建错误数据,如果它不太参与。
My question is: what is a good way to get this data from Android devices into the GAE datastore? 我的问题是:将这些数据从Android设备传输到GAE数据存储区的好方法是什么? If you could post a link to the appropriate Android libraries, or a link to how this has been done in the past, that would be really helpful. 如果您可以发布指向相应Android库的链接,或者指向过去如何完成此操作的链接,那将非常有用。
Nothing Android-specific about this -- just send an HTTP POST
to a GAE-served URL that will accept the request, process it, and store your data. 没有针对此的特定于Android的内容 - 只需将HTTP POST
发送到GAE服务的URL,该URL将接受请求,处理请求并存储您的数据。 There's no "Android-GAE" royal road
-- a POST
is just the normal way to perform this, whoever's sending it, whoever's serving it! 没有“Android-GAE” royal road
- POST
只是执行此操作的正常方式,无论是谁发送它,无论是谁服务它!
Yep, just send an http post. 是的,只需发送一个http帖子。 Here's a snippet of some code I used that worked fine on Android. 这是我使用的一些代码片段,在Android上运行良好。
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
try {
int TIMEOUT_MILLISEC = 10000; // = 10 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost(serverUrl);
request.setEntity(new ByteArrayEntity(
postMessage.toString().getBytes("UTF8")));
HttpResponse response = client.execute(request);
} catch (Exception e) {
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.