Venki
Venki

Reputation: 543

RestSharp returns Status '0' while calling post method

Am facing issue while consuming restful service POST method. It is showing Status code 0, but while am trying to give same request from POSTMAN rest client (A google chrome extension) it works fine. below is the code am using to post some data.

var client = new RestClient(colorCreateUrl);
var request = new RestRequest(Method.POST);
string jsonRequest = JsonConvert.SerializeObject(actColorRequest);
request.AddParameter("application/json; charset=utf-8", jsonRequest, ParameterType.RequestBody);
request.Timeout = 5000;
request.AddBody(jsonRequest);
var response = client.Execute(request);

Request : enter image description here

Error it shows

enter image description here

Upvotes: 0

Views: 5165

Answers (2)

Kosmas
Kosmas

Reputation: 385

I know this is an old question, but it seems the answer is not really helping. We should make the restClient throw any error. From there you can check the inner exception.

    var options = new RestClientOptions(_baseurl)
    {
        ThrowOnAnyError = true
    };
    _restClient = new RestClient(options);

Hope this can help anyone who face the same issues. Well, for me, it is just need to change to http.

Upvotes: 1

CodingBarfield
CodingBarfield

Reputation: 3398

Possibly you are using a self signed ssl certificate, check response.ErrorMessage for details. Either call an http endpoint or add the following code to allow all https certificates:

client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

I had the same issue today and used the above code to fix it.

Upvotes: 1

Related Questions