2017-07-30 112 views
1

我想张贴以下JSON与RestSharp:Restsharp API认证请求

{ "username": "test_user", "password": "super$3kretp4ssword" } 

所以这是C#代码我写

var client = new RestClient("https://accept.paymobsolutions.com/api/auth/tokens"); 
var request = new RestRequest(Method.POST); 
request.AddHeader("content-type", "application/json"); 
request.AddParameter("application/json", request.AddJsonBody(new { username = "myUsername", password = "myPassword" }), ParameterType.RequestBody); 
IRestResponse response = client.Execute(request); 

但在调试response.content""

回应应该是:

{ 
    "token": "ZXlKaGlPaUpJVXpVeE1pSX1Y0NJmV5Sn...", // this is your authentication token 
    "profile": { 
    "id": 28, // this is your merchant_id 
    "user": { 
     "id": 31, 
     "username": "test_user", 
     "first_name": "test_user", 
     "last_name": "test_user", 
    }, 
    "created_at": "2016-11-20T16:27:20.067296Z", 

    ... 
    } 
} 

Debugging Result Here

+0

什么'response'变量的其他领域? – Progman

+0

@Progman请参阅编辑 –

+0

不,您的'响应'变量的其他字段是什么?特别是'StatusCode'字段。 – Progman

回答

1

此异常有关ServicePointManager.SecurityProtocol

对于.NET 4使用以下方法来解决问题

ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;

0

发送个请求失败,因为“基础连接已经关闭:发生意外的错误......”。检查ErrorException字段以查看您的请求失败的原因。