Click here to Skip to main content
14,268,557 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have to access one Rest API thorough ASP.NET c#
It is working fine through POSTMAN
But i am getting Internal server error while accessing thorough code
Can anyone please help me?
Here my code:-

What I have tried:

var client = new RestClient("");
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var certFile = Path.Combine(@"D:\myproject\", "certificate1.pfx");
X509Certificate2 certificate = new X509Certificate2(certFile, "12345678)");
client.ClientCertificates = new X509CertificateCollection() { certificate };
client.Proxy = new WebProxy();
var restrequest = new RestRequest(Method.POST);
restrequest.AddHeader("Cache-Control", "no-cache");
restrequest.AddHeader("Accept", "application/json");
restrequest.AddHeader("Content-Type", "application/json");
restrequest.AddParameter("here i have added the request parameter",ParameterType.RequestBody);
IRestResponse response = client.Execute(restrequest);
Updated 12-Aug-19 2:56am
Richard MacCutchan 12-Aug-19 9:30am
You need to check the server logs.
Richard Deeming 13-Aug-19 11:10am
The request you're sending from your code does not match the request you're sending from Postman.

Use something like Fiddler[^] to capture both requests and compare them to find out what's different.

If you're still stuck, then contact the support team for the API you're trying to call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100