0

我有一个通过 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); 
4

2 回答 2

1

您需要使用HttpWebRequestHttpWebResponse类。代码可能看起来像这样(这些天我的 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()
于 2009-12-02T15:59:09.550 回答
0

请参阅:htmlentities 解决方案urlencode 解决方案

就 curl 而言,您似乎正在尝试调用 Web 服务。如果它是一个合适的 Web 服务(意味着某处有一个 WSDL 和一个 XSD),你应该在你的项目中添加一个服务参考(或者一个 Web 参考,如果你在 VS2005 或 VS2003 中),它将为你生成一个代理使用(而不是手动将 XML 转储到服务器)。

于 2009-12-02T15:57:58.897 回答