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

HttpWebRequestおよびHttpWebResponseクラスを使用する必要があります。コードは次のようになります (私の 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 があることを意味します)、サービス参照 (VS2005 または VS2003 を使用している場合は Web 参照) をプロジェクトに追加する必要があります。これにより、プロキシが生成されます。を使用します (手動で XML をサーバーにダンプする代わりに)。

于 2009-12-02T15:57:58.897 に答える