Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send XML via HTTP Post to IP:Port

Tags:

c#

http

post

xml

Ok so to start off, I'm not using any sort of web service. Right now I don't know a whole lot about the application receiving the XML other than it receives it. Big help there I know. I didn't write the receiving application but my company doesn't have any useful ways of testing the XML transmission phase.

I basically want to send an XML document like this...

<H2HXmlRequest class="myClass">
<Call>
    <CallerID></CallerID>
    <Duration>0</Duration>
</Call>
<Terminal>
    <CancelDate></CancelDate>
    <ClerkLoginTime></ClerkLoginTime>
</Terminal>
<Transaction>
    <AcceptedCurrency></AcceptedCurrency>
    <AccountId>6208700003</AccountId>
</Transaction>
</H2HXmlRequest>

...to the application that I don't really know a whole lot about. It's nothing fancy and with the proper help I could probably find out more info. But what I am looking to do is to come up with some kind of C# Forms app that can take that request above, send it on over using an IP and port, and hopefully see something happen.

like image 209
Steven Avatar asked Jul 08 '09 16:07

Steven


People also ask

How do I post XML to the server?

To post XML data to the server, you need to make an HTTP POST request, include the XML in the body of the request message, and set the correct MIME type for the XML. The correct MIME type for XML is application/xml.

How do I send an XML payload?

If you want to send XML data to the server, set the Request Header correctly to be read by the sever as XML. xmlhttp. setRequestHeader('Content-Type', 'text/xml'); Use the send() method to send the request, along with any XML data.

Can I send XML in REST API?

The REST API Client Service currently accepts only JSON input when making REST API Create, Read, Update, or Delete requests. It is nevertheless possible to use XML input when making REST API requests.

How do I send an XML file?

By default the XML files are saved in Documents > My ClickForms > UAD XML Files. 4. Double click on the XML file and this action will attach it to the email message. Then simply click on Send.


1 Answers

The recommended way to make simple web requests is to use the WebClient object.

Here's a code snippet:

// assume your XML string is returned from GetXmlString()
string xml = GetXmlString();


// assume port 8080
string url = new UriBuilder("http","www.example.com",8080).ToString();     


// create a client object
using(System.Net.WebClient client = new System.Net.WebClient()) {
    // performs an HTTP POST
    client.UploadString(url, xml);  

}
like image 102
Jeff Meatball Yang Avatar answered Sep 20 '22 14:09

Jeff Meatball Yang