Domanda

Ho un codice per inviare XML tramite POST. Ma questo codice è in PHP e ne ho bisogno in VB.NET.

Qualsiasi aiuto per convertire questo codice?

$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"; 

E come posso convertire questo codice PHP troppo:

$msg=htmlentities($msg);
$msg=urlencode($msg); 
È stato utile?

Soluzione

È necessario utilizzare il HttpWebRequest e HttpWebResponse classi. Il codice potrebbe sarebbe simile a questa ( il mio VB è un po 'arrugginito in questi giorni ):

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()

Altri suggerimenti

Si veda: htmlentities soluzione urlencode soluzione

E per quanto riguarda riccio, sembra che si sta cercando di chiamare un servizio web. Se si tratta di un servizio web corretto (cioè c'è un WSDL e un XSD da qualche parte), è necessario aggiungere un riferimento al servizio (o un riferimento Web se siete in VS2005 o VS2003) al progetto, che genererà un proxy per voi utilizzare (invece di pratiche di dumping manualmente XML a un server).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top