4
我已经编写了一个Web应用程序,使用Restlet框架在Google AppEngine上运行,并使用json与Web客户端进行通信。那些按预期工作。但是,通过Android访问时,编写的一个用于响应Android客户端的特定资源不起作用。但是,它通过网络浏览器访问时可以正常工作(我不会从浏览器发送请求参数,因此在这种情况下可以获得400这是可以的)。在Google AppEngine上运行已部署的应用程序的问题
public class PlayResource extends ServerResource {
private final float SCOREBASE = 1000.0F;
@Get
@Post
public JsonRepresentation play() {
try {
JsonRepresentation rep = new JsonRepresentation(getRequestEntity());
JSONObject inputJson = rep.getJsonObject();
JSONObject outputJson = new JSONObject();
String country = inputJson.optString("country");
outputJson.put("country", doSomething("country",country));
......
......
return new JsonRepresentation(outputJson);
} catch (IOException e) {
try {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new JsonRepresentation(
new JSONObject()
.put(Messages.TYPE_ERROR, Messages.BAD_REQUEST));
} catch (JSONException e2) {
setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
} catch (JSONException e) {
try {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new JsonRepresentation(
new JSONObject()
.put(Messages.TYPE_ERROR, Messages.BAD_FORMAT));
} catch (JSONException e2) {
setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
}
}
}
和客户端的Android设备运行验证码:
此代码对DevAppServer运行时,工作
Client client = new Client(Protocol.HTTP);
try {
JsonRepresentation requestJSON = new JsonRepresentation(new JSONObject()
.put("country", country.trim())
);
Request req = new Request(Method.GET,"http://****.appspot.com/resource/play",requestJSON);
Response resp = client.handle(req);
String res = resp.getEntity().getText();
JSONObject resultJSON = new JSONObject(res);
运行这一要求只是挂了Android客户端,服务器没有按”不要写任何建议请求没有到达的日志消息。
无响应的App Engine应用程序通常是由错误配置的app.yaml描述和/或缺少的处理程序引起的。你可以在这里包括这两个?这将有助于诊断问题。 – Greg 2011-04-11 19:18:44
您是否尝试过我的测试? – Panthro 2011-05-06 21:57:57