Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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
0
davoman
Asked:
davoman
  • 3
  • 2
1 Solution
 
drichardsCommented:
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.
0
 
drichardsCommented:
Also, sorry about the C# code.  Here's the VB version:

        Dim rq As WebRequest = WebRequest.Create(<server url>)
        rq.Method = "POST"
        Dim rqData As String = <your XML data>
        rq.ContentLength = rqData.Length
        Dim s As Stream = rq.GetRequestStream()
        Dim sw As StreamWriter = New StreamWriter(s)
        sw.Write(rqData)
        sw.Close()
        rq.GetResponse()
0
 
davomanAuthor Commented:
sorry took so long but had a problem with it not acctually posing any data doing the above
0
 
drichardsCommented:
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?
0
 
davomanAuthor Commented:
managed to adapte some other code but used this elsewhere cheers
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now