この PHP コードを VB.NET コードに変換するのに役立ちます。
質問
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);
解決
を使用する必要があります。 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()
他のヒント
を参照してください:にhtmlentitiesソリューションとでurlencode解決する
そして、あなたは、Webサービスを呼び出すしようとしているよう限りカールとして、それが見えます。それは適切なWebサービスだ場合にあなたのためのプロキシを生成します(あなたはVS2005やVS2003にいる場合またはWeb参照)、あなたは、あなたのプロジェクトにサービス参照を追加する必要があります(WSDLとどこかにXSDがあることを意味) (手動でサーバにXMLをダンプするのではなく)を使用します。
所属していません StackOverflow