我有一个通过 POST 发送 XML 的代码。但这段代码是 PHP 语言,我需要 VB.NET 语言。

有帮助转换此代码吗?

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

以及我如何转换此 PHP 代码:

$msg=htmlentities($msg);
$msg=urlencode($msg); 
有帮助吗?

解决方案

您需要使用 HttpWeb请求HttpWeb响应 类。代码可能看起来像这样(这几天我的VB有点生疏了):

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

其他提示

请参阅:ヶ辆溶液进行urlencode溶液

和尽可能卷曲,它看起来像你试图调用Web服务。如果这是一个正确的Web服务(意思是有一个WSDL和XSD的地方),你应该添加一个服务引用(或Web引用,如果你在VS2005或VS2003是)到你的项目,这将产生一个代理为你使用(而不是手动倾倒XML到服务器)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top