只有在重新启动服务时Aplication才会挂起,而在服务器正在运行或停止时不会挂起,

在Google网上论坛上有一个关于此问题的讨论,我不知道它是否与Android模拟器有关。 https://groups.google.com/forum/#!topic/restsharp/SMl7sBN72xE

class WService {

    static string BaseUrl = "http://Server:8732/Service1/";

    public static void ExecuteAndGetRestResponse(string controller, JObject data, Action<Object> callbackRespuesta)
    {

        try {

            var json = JsonConvert.SerializeObject(data);

            var request = new RestRequest(controller, Method.POST);
            request.AddParameter("text/json", json, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;
            request.Timeout=10000;

            ExecuteAndGetRestResponse(request,  callbackRespuesta);
        }
        catch{

            Log.Info ("Testing", "ExecuteAndGetRestResponse No descripcion");
        }
    }

    static void ExecuteAndGetRestResponse(RestRequest request, Action<Object> callbackRespuesta)
    {

        var client = new RestClient();
        client.BaseUrl = BaseUrl;

            try {
                client.ExecuteAsync (request, response => {
                    Log.Info ("Testing", "si se lanza");

                    try {
                        callbackRespuesta (response);

                    } catch (Exception e) {
                        callbackRespuesta (e);
                    } 


                });

            } catch (Exception e) {
                Log.Info ("Testing", e.Message);
                callbackRespuesta (e); 

            }

    }
    }

===============>>#1 票数:0 已采纳

您是否尝试过设置超时时间? client.Timeout = 1000; 这将是1秒。

我尝试了所有默认代码,并且一切正常。

var client = new RestClient ("http://hellodadfadf");
client.Timeout  = 1000;
var request = new RestRequest (String.Format ("{0}/allinfo", "198440"));
client.ExecuteAsync (request, response => {
  Console.WriteLine (response.Content);
});

您还传递请求吗? 没有完整的逻辑,很难调试代码。

  ask by Ces TR translate from so

未解决问题?本站智能推荐: