Solved

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

Posted on 2013-05-27
3
7,379 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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