Link to home
Start Free TrialLog in
Avatar of mmalik15
mmalik15

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmalik15
mmalik15

ASKER

Thanks for the comments. I guess you guys are right as there seems to be an issue at the server end authentication.