none
403 Forbidden error using WebClient but works in web browser RRS feed

  • Question

  • I have a C# app that calls a web service. If I call the service via my web browser (by simply copy-and-pasting it into the address bar) it works:

    http://staging-sa.denovu.com/property/webservice/export/propworx?branchid=cx0319&propertyid=39

    But if I do the same with my web, using either WebClient or HttpWebRequest, I get a 403 Forbidden error.

    I've read that this could be a simple matter of setting the User Agent header, but I've tried a dozen alternatives and non have worked. Here is my code:

    string sURL = @"http://staging-sa.denovu.com/property/webservice/export/propworx?branchid=cx0319&propertyid=39"
    string result = "";
    using (WebClient webClient = new WebClient())
    {
        //webClient.Headers.Add(HttpRequestHeader.UserAgent, "tried many things here....");    
        // I also tried this:                    
        //webClient.Headers.Add("accept", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        result = webClient.DownloadString(sURL);
    }
    

    Any ideas? The app is a WPF .Net 4.7 app running in Windows Server 2012 R2.

    Thanks...


    Fabricio Rodriguez - Pretoria, South Africa

    Thursday, October 26, 2017 1:41 PM

Answers

All replies