Solved

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

Posted on 2013-05-27
3
5,793 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 74

Accepted Solution

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

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

8 Experts available now in Live!

Get 1:1 Help Now