이 PHP 코드를 VB.NET 코드로 변환하는 데 도움이됩니다
문제
게시물을 통해 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 솔루션
그리고 Curl까지는 웹 서비스를 호출하려고하는 것처럼 보입니다. 적절한 웹 서비스 (WSDL과 XSD가 있음을 의미하는 경우) 인 경우 프로젝트에 서비스 참조 (또는 VS2005 또는 VS2003에있는 경우 웹 참조)를 추가해야합니다. XML을 수동으로 서버에 덤프하는 대신 사용하십시오.
제휴하지 않습니다 StackOverflow