Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-27
3
Medium Priority
?
10,810 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 1000 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

916 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