【发布时间】:2014-10-08 14:15:10
【问题描述】:
我遇到了一个重大问题,希望有人能提供帮助。
我们有使用 Parse 作为后端的 Web 和 Android 应用程序。我们在这两个方面都发生了这个问题。我将解释Android问题。
我们使用 REST API 将数据保存到 Parse.com。我们不使用 SDK 的原因是我们想利用仅在 RESTAPI 中可用的批处理操作。
{
"requests": [
{
"body": {
"isFriable": false,
"haDetail": "",
"sizeOther": "",
"colourOther": "",
"texture": "",
"fieldInspection": {
"__type": "Pointer",
"className": "FieldInspection",
"objectId": "YS5bXHBwDu"
},
"surfaceSubType": {
"__type": "Pointer",
"className": "SurfaceSubType",
"objectId": "d4IL5k1pv5"
},
"size": {
"__type": "Pointer",
"className": "HomogenousMaterialSize",
"objectId": "ezr3uHDUvt"
},
"colour": {
"__type": "Pointer",
"className": "HomogenousMaterialColour",
"objectId": "NqYXJcOkPE"
}
},
"method": "POST",
"path": "/1/classes/HomogenousArea"
}
]
}
以上是我的要求。使用基本的默认 HttpClient 将其推送到 https://api.parse.com/1/batch。
当我们执行 HTTP 请求时,它有时会挂起,不会返回任何结果。大约每 5 或 6 个请求中就有一个这样做。成功的后续请求中完全相同的数据将正常通过。问题是那时我们有重复的记录持久化到 Parse,因为我们的同步逻辑从未完成,因为我们没有得到响应。
Parse 中有什么东西可以用来调试这样的请求吗?下面是我们正在使用的当前 http 客户端实现。注意:还从 Square 中放入 OkHttp 并遇到完全相同的问题。
// Instantiate the http client to make the batch request
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = setupHttpPost(url);
// Assign the data to the post
StringEntity entity = new StringEntity(insertData);
post.setEntity(entity);
// Setup the response handler
ResponseHandler response = new BasicResponseHandler();
// Make the call to Post the new data
Object rersponse = httpClient.execute(post, response);
if (rersponse != null) {
return rersponse.toString();
}
return null;
【问题讨论】:
标签: android http parse-platform response