我试图查询我的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;
}
}
您正在使用哪个平台? “响应”变量是否为“StatusCode”集? –
我正在使用visual studio 2017,没有'response'变量不为null,'StatusCode'设置为0; –
我的意思是iOS,Android,UWP作为平台。是否设置了'response'的ErrorMessage属性? –