Solved

how to fix "The remote server returned an error: (403) Forbidden"

Posted on 2013-05-27
3
6,336 Views
Last Modified: 2013-05-28
This error has been asked several times across different forums and sites. I have tried nearly all the solutions but still unable to fix it. My code is as below.

public XmlDocument PlaceOrder(DeliveryModel model, BIUser theUser, Guid orderId, illunit theUnit, string speed)
    {
        string xmlToPost = ConstructXMLOrderRequest(model, theUser, orderId, theUnit, speed);
        string authParams = GenerateAuthenticationString(xmlToPost, theUnit.bl_acc);
        string rootUrl = configurationLogic.LibraryAPIUrl;
        Encoding enc = System.Text.Encoding.GetEncoding(1252);
        string requestString = rootUrl + "orders";

        HttpWebRequest apiCall = (HttpWebRequest)WebRequest.Create(requestString);

        apiCall.Headers.Add("BLDSS-API-Authentication", authParams);


        byte[] byteArray = ASCIIEncoding.UTF8.GetBytes(xmlToPost);
        apiCall.Accept = "*/*";
        apiCall.KeepAlive = false;
        apiCall.AllowAutoRedirect = false;
        apiCall.Method = "POST";
        apiCall.ContentType = "text/xml";
        apiCall.ContentLength = byteArray.Length;
        apiCall.UserAgent = "Code Sample Web Client";

        Stream dataStream = apiCall.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        HttpWebResponse webresponse;
        webresponse = (HttpWebResponse)apiCall.GetResponse();

        StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
        string response = loResponseStream.ReadToEnd();

        XmlDocument toReturn = new XmlDocument();
        toReturn.LoadXml(response);

        return toReturn;
    }

Open in new window


thanks
0
Comment
Question by:mmalik15
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39199240
Are you certain your URL and your authentication parameters are correct? How does authentication work with this target site?
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39199380
This page says that 403 means it recognizes you but still isn't going to allow access.  http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error   That pretty much means that the server admin has to fix it to allow you access.

Does your code work with any other site?
0
 

Author Comment

by:mmalik15
ID: 39201714
Thanks for the comments. I guess you guys are right as there seems to be an issue at the server end authentication.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now