Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent of Visual Basic API call

Tags:

c#

vba

I have inherited a API which gives a Visual Basic example of how to call the API which is below:

Dim sPost As String
Dim sAction As String
Dim sXMLData As String
Dim sHTTPHeaders As String
sPost = "POST"
sAction = "http://MyHost/1/XmlService"
sXMLData = "<xml ..> <request …….. /></xml>"
sHTTPHeaders = "Content-type: text/xml"
Inet1.Execute sAction, sPost, sXMLData, sHTTPHeaders

I am familar with using HttpWebRequest and have no issue setting the content type, method etc but I am not sure how to set the sXMLData - which property of my HttpWebRequest would I set?

Thanks in Advance.

like image 401
andrewb Avatar asked Jul 26 '26 20:07

andrewb


1 Answers

It looks like you'd want to write that XML data to the request body. To do that, you normally create a StreamWriter using HttpWebRequest.GetRequestStream():

// HttpWebRequest request;
// string sXmlData;

using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
{
    sw.Write(sXmlData);
}
like image 91
McGarnagle Avatar answered Jul 29 '26 11:07

McGarnagle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!