locked
What can I do to correct this error in my HttpWebRequest, The Requested Resource can only be accessd via SSL RRS feed

  • Question

  • User-809400599 posted

    the error is happening on the line : var authResponse = authRequest.GetResponse();

    Internal Server Error 500 : Protocol Error : The Requested Resource can only be accessed via SSL

    What I don't know is if there is anything I can do in my code below, or if they remedy is required on my Server that I am attempting to access via "HttpWebRequest"

    To the best my knowledge that server is SSL enabled, but how do I find out?

    Here is the code:

    public static void PostMedia2()
    {
    try
    {
    var authUrl = "https://intranet-dev.university.edu/sitecore/api/ssc/auth/login";
    var authData = new Authentication
    {
    Domain = "sitecore",
    Username = "admin",
    Password = "b"
    };

    var authRequest = (HttpWebRequest)WebRequest.Create(authUrl);

    authRequest.Method = "POST";
    authRequest.ContentType = "application/json";

    var requestAuthBody = JsonConvert.SerializeObject(authData);

    var authDatas = new UTF8Encoding().GetBytes(requestAuthBody);

    using (var dataStream = authRequest.GetRequestStream())
    {
    dataStream.Write(authDatas, 0, authDatas.Length);
    }
    CookieContainer cookies = new CookieContainer();

    authRequest.CookieContainer = cookies;

    var authResponse = authRequest.GetResponse(); <-- Internal Server Error 500 on the GetResponse()

    Console.WriteLine($"Login Status:\n\r{((HttpWebResponse)authResponse).StatusDescription}");

    authResponse.Close();

    var emailObj = new ItemRequest
    {
    ItemName = "Class Lists Phase Resuls",
    TemplateID = "{0603F166-35B8-469F-8123-E8D87BEDC171}",
    Title = "Cless List Test June",
    Text = "Class List Test June 2020"
    };
    var url = "https://intranet-dev.university.edu/sitecore/api/ssc/item/sitecore%2Fmedia%20library%PtrTest4";

    var request = (HttpWebRequest)WebRequest.Create(url);

    request.Method = "POST";
    request.ContentType = "application/json";
    request.CookieContainer = cookies;

    var requestBody = JsonConvert.SerializeObject(emailObj);

    var data = new UTF8Encoding().GetBytes(requestBody);

    using (var dataStream = request.GetRequestStream())
    {
    dataStream.Write(data, 0, data.Length);
    }

    // var response = request.GetResponse();

    using (WebResponse response = request.GetResponse())
    {
    Console.WriteLine($"Item Status:\n\r{((HttpWebResponse)response).StatusDescription}");
    }


    }

    catch (WebException ex)
    {
    Console.WriteLine($"Error occurred. Message: {ex.Message}.\r\n StackTrace: {ex.StackTrace}.\r\n InnerException: {ex.InnerException}");
    }

    Console.ReadKey();
    }

    Wednesday, June 10, 2020 7:26 PM

All replies

  • User-2054057000 posted

    Seems your API needs clients to have ssl installed. You haven's shown your API Controller's Code. 

    You can check the API action method which is being called and comment out the [RequireHttps] attribute.

    //[RequireHttps]  
    public IEnumerable<string> Get ()  
    {  
        //...  
    }  

    Thursday, June 11, 2020 2:31 AM
  • User-809400599 posted

    I am going to try to work with my Infrastructure team and see what they can assist me with.

    I did not write the Web Api so I have no control over its code. The Web Api is part of a vendor package. Sitecore

    I may also put in a ticket to them.

    Best Regards,

    Thursday, June 11, 2020 11:33 AM
  • User-474980206 posted

    The message may be misleading, perhaps the payload structure is invalid (is your json serializer set to camelcase?). I'd try first with postman. 

    Thursday, June 11, 2020 9:23 PM
  • User-809400599 posted

    Thank you for taking the time to respond. I have a couple of ideas and I think you are right. I can't even get authenticated.

    Thursday, June 11, 2020 9:41 PM
  • User1686398519 posted

    Hi ptrykiel,

    "Internal Server Error 500" is caused by the API you are calling. You can contact the API you requested to consult your problem.

    Best Regards,

    YihuiSun

    Friday, June 19, 2020 9:24 AM