Trevor Daniel
Trevor Daniel

Reputation: 3974

Post JSON over HTTPS

In the past I have successfully called a JSON webservice over HTTP But, now I have to make a JSON POST over HTTPS.

I have tried using the code that works for HTTP and simply changed the url that is being called to https but it won't work.

This is the code i am using...

WebRequest wrGETURL;
wrGETURL = WebRequest.Create("https://apitest.example.com/geo/coverage/v1/?appId=2644571&appKey=836621d715b6ce4db5f007d8fa2214f");
wrGETURL.Method = "POST";
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
string responseFromServer = objReader.ReadToEnd();

and the error message i am seeing in fiddler is:

fiddler.network.https> Failed to secure existing connection for apitest.example.com. A call to SSPI failed, see inner exception. InnerException: System.ComponentModel.Win32Exception (0x80004005): The client and server cannot communicate, because they do not possess a common algorithm

Can anyone help me with that I need to do to make a call over HTTPS please?

Upvotes: 1

Views: 6400

Answers (2)

Tim Flinn
Tim Flinn

Reputation: 61

I am using React and Expressjs and ran into this issue. Send your ie: https://www.google.com with out the https:

part of my router.js

    router('/vod')
    .rout.get('/vod', (req,res)=>{
    res.send({message: "//www.google.com"});

App.js

    function App() {
    const [vod, setVod] = React.useState(null);
    
    React.useEffect(() => {
            fetch("/vod")
                .then((res) => res.json())
                .then((vod) => setVod(vod.message));
        },
        []);

    return (

        <div className="App">
            <header className="App-header">
                <iframe src={"https:"+vod} 
   id="myIframe" autoPlay width={1000} height= 
   {500} frame></iframe>
            </header>
        </div>

    );

in the iframe to change the source I used {"https:"+vod} to simulate the full url.

in your case try to combine your "result" like ("https:"+result)

I noticed that json grabs the : and messes the string up.

Upvotes: 0

joel
joel

Reputation: 527

Do you need to authenticate or maybe a callback for the server certificate? This works for me in most cases:

        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://someurl/");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "POST";

        // Create NetworkCredential Object 
        NetworkCredential admin_auth = new NetworkCredential("username", "password");

        // Set your HTTP credentials in your request header
        httpWebRequest.Credentials = admin_auth;

        // callback for handling server certificates
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{\"name\":\"TEST_123\"}";
            streamWriter.Write(json); 
            streamWriter.Flush();
            streamWriter.Close();
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Console.WriteLine(result);
            }
       }

Upvotes: 1

Related Questions