C# REST API身份验证请求
我试图用RestSharp发布以下JSON:C# REST API身份验证请求,c#,restsharp,C#,Restsharp,我试图用RestSharp发布以下JSON: { "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
{ "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);
但是在调试响应时,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",
...
}
}
发送请求失败,因为“基础连接已关闭:发生意外错误…”。检查
ErrorException
字段以查看请求失败的原因。此异常与ServicePointManager.SecurityProtocol
对于.NET4,请使用以下方法解决此问题
ServicePointManager.SecurityProtocol=(SecurityProtocolType)768 |(SecurityProtocolType)3072代码>响应变量的其他字段是什么?@Progman请查看编辑号,响应变量的其他字段是什么?特别是StatusCode
field.response.StatusCode=0response
变量中的所有字段是什么?请编辑该问题,以包括所有字段及其从响应
变量中获得的值。它们可能包含请求失败的原因。在您的例子中,看起来它甚至没有发送到服务器。