Reputation: 89
I am trying to post the following JSON with RestSharp:
{ "username": "test_user", "password": "super$3kretp4ssword" }
so this is the c# code i wrote
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);
But on debugging the response.content
is ""
The response should be:
{
"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",
...
}
}
Upvotes: 1
Views: 1798
Reputation: 89
This exception is related to ServicePointManager.SecurityProtocol
For .NET 4 use the following to solve the problem
ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
Upvotes: 1
Reputation: 19545
Sending th request failed because "The underlying connection was closed: An unexpected error occurred ...". Check the ErrorException
field to see the reason why your request failed.
Upvotes: 0