MVC not seeing https web api

Viewed 32

C# SSL security certificate wizard needed!

Postman works, SoapUI works, my code gets a 404!

I have created a C# 4.7.2 MVC Web application. It makes a RestRequest().Post to a C# WebApi hosted on iis. This all works properly and as expected on http.

Now I want to make it https, I have added a security certificate to iis. Now I have problems.
If I make the request via Postman or SoapUI I get the response as before no problem. When I make the call with my C# HelperApp I get a 404 back! (Of course I checked the address path a thousand times.) The 404 really confuses things. It's definitely there and we are hitting it successfully with Postman and SoapUI.

I suspect that I am not telling the RestClient to use SSL?

TIA.

                   case "Submit":

                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | SecurityProtocolType.SystemDefault;  
                    
                    var apiServer = Startup.Config.ApiUrl; // this points to web.config <add key="API_URL" value="https://xxx.yyy.local:444/" />   
                    //It works when I use <add key="API_URL" value="http://IEAVNBQ02:85/" />

                    var baseUrl = apiServer + $"api/ProcessQuotes/";

                    var client = new RestClient(baseUrl);
                    client.Options.MaxTimeout = -1;
          
                    
                    var request = new RestRequest();
                    request.Method = Method.Post;


                    request.AddHeader("Content-Type", "application/json");
                    request.AddParameter("application/json", model.JsonRequest, ParameterType.RequestBody);
                    var response = client.Execute(request);

var Response is populated with:

<title>Network Error: 404</title>
<meta name="description" content="Proxy Exception: Network Error: 404" />
1 Answers

You may need to set

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

before making a call.

Just keep in mind this is a global setting.

Related