帮助将此 PHP 代码转换为 VB.NET 代码

发布于 2024-08-14 03:05:57 字数 767 浏览 7 评论 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); 

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晌融 2024-08-21 03:05:57

您需要使用 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()

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()
走走停停 2024-08-21 03:05:57

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

至于curl,看起来你正在尝试调用一项网络服务。如果它是一个正确的 Web 服务(意味着某处有 WSDL 和 XSD),您应该向您的项目添加一个服务引用(如果您使用的是 VS2005 或 VS2003,则添加一个 Web 引用),这将为您生成一个代理使用(而不是手动将 XML 转储到服务器)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文