Link to home
Start Free TrialLog in
Avatar of davoman
davomanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using HTTP Post with XML

Hi there

I am uploading some data in XML format and they NEED it in an HTTP Form post but not sure how to do that. Can anyone point me in the right direction
Avatar of drichards
drichards

You can use a WebRequest:

            WebRequest rq = WebRequest.Create("<server url>");
            rq.Method = "POST";
            // If your XML data is not in a string, you just need to get its length,
            // set the ContentLength, and write the data to the RequestStream.
            string rqData = <your XML data>;
            rq.ContentLength = rqData.Length;
            Stream s = rq.GetRequestStream();
            StreamWriter sw = new StreamWriter(s);
            sw.Write(rqData);
            sw.Close();
            WebResponse wr = rq.GetResponse();
            // Handle response...


You may also need to set some other headers like ContentType, etc.  Talk to the server implementers about what headers are required/expected.
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

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 davoman

ASKER

sorry took so long but had a problem with it not acctually posing any data doing the above
What exactly is your code and how do you know it is not posting anything?  As they say: "it works on my machine".  Do you capture the network traffic?  Or put another way, can you tell if the problem is that the data is not posted or that you are just not reading it properly in the server code?
Avatar of davoman

ASKER

managed to adapte some other code but used this elsewhere cheers