Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# REST API身份验证请求_C#_Restsharp - Fatal编程技术网

C# REST API身份验证请求

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

我试图用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-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=0
response
变量中的所有字段是什么?请编辑该问题,以包括所有字段及其从
响应
变量中获得的值。它们可能包含请求失败的原因。在您的例子中,看起来它甚至没有发送到服务器。