Click here to Skip to main content
15,302,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I am posting XML file to Web services using C# .
My work is generating a xml file from object of my application then I should send it on the business Gateway of Monster.com .
I tried this method for sending but I encountred an error "The remote server returned an error: (403) Forbidden."
Please Help !


public void sendFileToWebservice(string file)
        {
            string xmlString = System.IO.File.ReadAllText("C:/Users/DELL/Documents/Visual Studio 2012/Projects/testXML/testXML/file.xml");
            string url = "https://gateway.monster.com:8443/bgwBroker";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);


            byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xmlString);
            req.Method = "POST";
            req.ContentType = "text/xml;charset=utf-8";
            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();


            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
            string backstr = sr.ReadToEnd();
            sr.Close();
            res.Close();
}
Posted

1 solution

Please refer the following Link
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900