[英]GAE Reading from Datastore
I want to return myHighscores from Datastore: ie: Paul,1200 Tom,1000 Kevin,800 我想从数据存储区返回myHighscores:即:Paul,1200 Tom,1000 Kevin,800
private void returnHighscores(HttpServletResponse resp, String game, int max) throws IOException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Query query = new Query("highscore", gameKey);
query.addSort("points", Query.SortDirection.DESCENDING);
List<Entity> highscores = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(max));
for(Entity e : highscores) {
resp.getWriter().println(e.getProperty("name") + "," + e.getProperty("points"));
}
}
and it is working :) ! 它正在工作:)! But when I want to read the returned Highscores and add the String to a textView with: 但是当我想阅读返回的Highscores并将String添加到textView时,具有:
AndroidHttpClient client = AndroidHttpClient.newInstance("Mueckenfang");
HttpPost request = new HttpPost(HIGHSCORE_SERVER_BASE_URL + "?game=" + HIGHSCORESERVER_GAME_ID);
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStreamReader reader = new InputStreamReader(entity.getContent(), "utf-8");
int c = reader.read();
while (c > 0) {
highscores += (char) c;
c = reader.read();
}
TextView tv = (TextView) findViewById(R.id.highscoreTv);
tv.setText(highscores);
I only get some HTML code like: 我只得到一些HTML代码,例如:
><html><head><meta http-euiv="content-type"content="text/html;charset=utf-8"><title>405 GTTP method POST is....
But i want something like Paul,1200 Tom,1000 Kevin 800 and so on 但是我想要Paul,1200 Tom,1000 Kevin 800等
HttpPost not accepted query parameter, as like "?game=" + HIGHSCORESERVER_GAME_ID.
HttpPost不接受查询参数,例如"?game=" + HIGHSCORESERVER_GAME_ID.
you need to pass that values as 您需要将该值传递为
AndroidHttpClient client = AndroidHttpClient.newInstance("Mueckenfang");
HttpPost request = new HttpPost(HIGHSCORE_SERVER_BASE_URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("game", String.valueOf(HIGHSCORESERVER_GAME_ID)));
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
The issue is your handler on appengine supporting only http 'GET'( I think you are overriding only doGet) but you are using 'POST' from the client. 问题是您在Appengine上的处理程序仅支持http'GET'(我认为您仅覆盖doGet),但是您正在从客户端使用'POST'。 Change the http method on client side to 'GET'. 将客户端的http方法更改为“ GET”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.