1

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", ... } } 

Debugging Result Here

6
  • What are the other fields of the response variable? Commented Jul 30, 2017 at 16:21
  • @Progman please see the edit Commented Jul 30, 2017 at 16:27
  • No, what are the other fields of your response variable? Specially the StatusCode field. Commented Jul 30, 2017 at 16:31
  • response.StatusCode = 0 Commented Jul 30, 2017 at 16:34
  • What are all the fields from the response variable? Please edit the question to include all the fields and the values they have from the response variable. They might contain information why the request failed. In your case, it looks like it wasn't even send to the server. Commented Jul 30, 2017 at 16:36

2 Answers 2

1

This exception is related to ServicePointManager.SecurityProtocol

For .NET 4 use the following to solve the problem

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.