none
Webrequest getting Error RRS feed

  • General discussion

  • public bool IsConnected(string _url)
     {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    var requestUri = new Uri(_url);
    WebRequest request = WebRequest.Create(requestUri);
    try
    {
        request.GetResponse().Close();
              request = null;
      return true;
    }
    catch
    {
      request = null;
    return false;
    }
     }
    Wednesday, May 15, 2019 5:52 AM

All replies

  • What error are you getting?
    Wednesday, May 15, 2019 8:37 AM
  • Hi Kem,

    I get below the error

    "sendfailure (error writing headers) " as well as attached error image link below.

    https://ibb.co/5n025dJ

    Regards

    Thiru


    Wednesday, May 15, 2019 9:11 AM
  • What is the URL you are connecting to?

    As a style note, instead of hardcoding a magic number, you should use the correct value:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, May 15, 2019 6:31 PM
  • You're not passing any headers so is this coming from the actual call or the response from the remote end? If the error is coming from the remote end then it might be that the remote end expects headers (which we would have no way of knowing) and you aren't providing them.

    Catching the actual exception and showing us the message, callstack and any underlying HTTP information would be useful. You can also use Fiddler to watch the network traffic and get the request you send and the response that was returned.

    Please, when posting code, use the Insert Code Block tool in the editor so we can see your code more easily.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, May 16, 2019 2:48 PM
    Moderator