2017-05-14 278 views
0

我试图查询我的mlab mongodb数据库上的数据与他们的休息API,但我无法得到它工作。RestSharp http statut代码和响应statut 0“错误:SecureChannelFailure(验证或解密失败)”

为了在我的Xamarin应用程序中创建Http休息请求我使用了restSharp,我尝试了很多次,但我总是得到一个空的答案,而不是事件标题,所以我真的不知道问题来自哪里。

这里是我的代码:

class HttpDataHandler 
{ 
    static String stream = null; 
    public String GetHttpData(String collection) 
    { 
     var uri = "https://api.mlab.com"; 

     var client = new RestClient(uri); 

     var request = new RestRequest("api/1/databases/{db}/collections/{coll}" , Method.GET); 
     request.AddParameter("apiKey", Common.API_KEY); // adds to POST or URL querystring based on Method 
     request.AddUrlSegment("db", Common.DB_NAME); 
     request.AddUrlSegment("coll", collection); 

     IRestResponse response = client.Execute(request); 

     if (response.StatusCode == System.Net.HttpStatusCode.OK) 
      System.Console.WriteLine(response.Content); // raw content as string 
     else 
      System.Console.WriteLine(response.StatusDescription + " " + response.ResponseUri+" "+ response.StatusCode); 

     return stream; 
    } 
} 
+0

您正在使用哪个平台? “响应”变量是否为“StatusCode”集? –

+0

我正在使用visual studio 2017,没有'response'变量不为null,'StatusCode'设置为0; –

+0

我的意思是iOS,Android,UWP作为平台。是否设置了'response'的ErrorMessage属性? –

回答

0

MLAB使用TLS1.2。将您的Android项目的SSL/TLS实施从Default更改为Native TLS 1.2+很可能会解决此问题。

请参阅the HttpClient Stack and SSL/TLS documentation了解Xamarin Android项目中提供的这两个组合框的详细说明。

+0

非常感谢你提姆这是问题 –

相关问题