如何在Parse查询中包含超时? [英] How to include timeout on Parse queries?

查看:270
本文介绍了如何在Parse查询中包含超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于Android的parse.com查询以及如果查询花费太长时间来响应,如何设置超时。

my question is on parse.com queries for Android and how to set a timeout if queries are taking too long to respond.

例如,我有一个查询我从parse.com获取字符串列表。如果此查询从parse.com收到的时间太长(例如,十秒),我希望用户能够取消查询(例如,使用屏幕弹出窗口)。相反,应用程序在等待30秒后崩溃。

For example, I have a query where I am getting a list of strings from parse.com. If this query takes too long to be received from parse.com (say, ten seconds), I'd like the user to be able to cancel the query (with an on-screen pop-up, for example). Instead, the app crashes after 30+ seconds of waiting.

那么,有没有办法为查询设置自己的超时,然后适当地处理它们?

So, is there a way to set my own timeout for queries, then handle them appropriately?

推荐答案

Https是与解析连接的协议。

Https is the protocol for connections with parse.

Http (s)允许完全控制以下内容:

Http(s) allows full control of the following:

套接字超时

getConnection超时

getConnection timeout

connectionRequest超时

connectionRequest timeout

为了操纵标题,我知道使用parse.com你可以使用Rest API然后用你在构建器中的标题做你想做的任何事情....

In order to manipulate the headers, i know that with parse.com you can use the Rest API and then do anything u want with the headers in the builder....

public void create(int method, final String url, final String data) {
    this.method = method;
    this.url = url;     
    this.data = data;
    if(method == GET){
        this.config = RequestConfig.custom()
            .setConnectTimeout(6 * 1000)
            .setConnectionRequestTimeout(30 * 1000)
            .setSocketTimeout(30 * 1000)                
            .build();
    } else{
        this.config = RequestConfig.custom()
                .setConnectTimeout(6 * 1000)
                .setConnectionRequestTimeout(30 * 1000)
                .setSocketTimeout(60 * 1000)                
                .build();           
    }
    this.context = HttpClientContext.create(); 

如果你只使用android sdk,那么你需要在parse.com上的文档来弄清楚如何(或者是否可能)设置上面列出的http连接配置。

If you use only android sdk, then you will need docs at parse.com to figure out how ( or whether possible ) to set the http connection config listed above.

这篇关于如何在Parse查询中包含超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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