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.
thanks
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;
}
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER