Help to convert this PHP code to VB.NET code
Question
I have a code to send XML via POST. But this code is in PHP and I need it in VB.NET.
Any help to convert this code?
$XMLFile= (here i have created the xml file. XML is encoded ISO-8859)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"URL WHERE I SEND XML");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"XMLDATA=".$XMLFile);
$results=curl_exec ($ch);
curl_close ($ch);
$results=stripslashes($results);
$xmlreturned=new SimpleXMLElement($results);
if($xmlreturned->NotificationResultHeader->RRC==0){
if($xmlreturned->NotificationResultList->NotificationResult->NRC==0){
echo "OK. SUCCES";
And how I convert this PHP code too:
$msg=htmlentities($msg);
$msg=urlencode($msg);
Solution
You need to use the HttpWebRequest and HttpWebResponse classes. The code could would look something like this (my VB is a bit rusty these days):
Dim xmlDoc as XmlDocumnet
'
' prepare you xml doc here...
'
Dim encoding as ASCIIEncoding = New ASCIIEncoding()
Dim postData as String
postData = "XMLDATA=" + xmlDoc.ToString()
Dim data() as Byte
data = encoding.GetBytes(postData)
' Prepare web request...
Dim myRequest as HttpWebRequest
myRequest = CType(WebRequest.Create("URL TO POST HERE"), HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType="application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream as Stream = myRequest.GetRequestStream()
' Send the data.
newStream.Write(data, 0, data.Length)
' Get the response
Dim myResponse as HttpWebResponse
myResponse = myRequest.GetResponse()
OTHER TIPS
See: htmlentities solution and urlencode solution
And as far as curl, it looks like you're trying to call a web service. If it's a proper web service (meaning there is a WSDL and an XSD somewhere), you should add a Service Reference (or a Web Reference if you're in VS2005 or VS2003) to your project, which will generate a proxy for you to use (instead of manually dumping XML to a server).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow