How do I convert the below PHP code to VB.NET?
Posted
by Greg
on Stack Overflow
See other posts from Stack Overflow
or by Greg
Published on 2010-03-12T12:35:54Z
Indexed on
2010/03/12
12:47 UTC
Read the original article
Hit count: 315
How do I convert the below PHP code to VB.NET?
<?php
$X_HOST ="foo.com";
$X_URL = "/index.php";
$X_PORT ="8080";
$X_USERNAME = "foo";
$X_PASSWORD = "bar";
$s_POST_DATA = "Channel=UK.VODAFONE"; // Channel
$s_POST_DATA .= "&Shortcode=12345"; // Shortcode
$s_POST_DATA .= "&SourceReference=3456"; // Source Reference
$s_POST_DATA .= "&MSISDN=447811111111"; // Phone
$s_POST_DATA .= "&Content=test"; // Content
$s_POST_DATA .= "&DataType=0"; // Data Type
$s_POST_DATA .= "&Premium=1"; // Premium
$s_POST_DATA .= "&CampaignID=4321"; // CampaignID
$s_Request = "POST ".$X_URL." HTTP/1.0\r\n";
$s_Request .="Host: ".$X_HOST.":".$X_PORT."\r\n";
$s_Request .="Authorization: Basic ".base64_encode($X_USERNAME.":".$X_PASSWORD)."\r\n";
$s_Request .="Content-Type: application/x-www-form-urlencoded\r\n";
$s_Request .="Content-Length: ".strlen($s_POST_DATA)."\r\n";
$s_Request .="\r\n".$s_POST_DATA;
//Sends out the request to the server.
$fp = fsockopen ($X_HOST, $X_PORT, $errno, $errstr, 30) or die("Error!!!");
fputs ($fp, $s_Request);
while (!feof($fp)) {
$s_GatewayResponse .= fgets ($fp, 128);
}
fclose ($fp);
//Array of official response codes.
$a_Responses = array(
"100" => "Server has returned an unspecified error.",
"101" => "Server successfully received the request.",
"102" => "Server has returned an database error",
"103" => "Server has returned an syntax error."
);
echo "<HTML>\n<BODY>\n\n";
//Checks for an official response code.
foreach ($a_Responses as $s_ResponseCode => $s_ResponseDescription) {
if (stristr($s_GatewayResponse, "\n$s_ResponseCode\n")) {
echo "A response code of $s_ResponseCode was returned – ";
echo $s_ResponseDescription";
$b_CodeReturned = true;
}
}
//Checks for an authorization failure where an official response code has
//not been recognized.
if (!$b_CodeReturned) {
if (stristr($s_GatewayResponse, "HTTP/1.1 401")) {
echo "The server rejected your username/password (HTTP 401).";
} else {
echo "No recognised response code was returned by the server.";
}
}
echo "\n\n</BODY>\n</HTML>";
?>
and
<?php
$s_ref = $HTTP_POST_VARS["Reference"]; // Reference
$s_trg = $HTTP_POST_VARS["Trigger"]; // trigger
$s_shc = $HTTP_POST_VARS["Shortcode"]; // shortcode
$s_pho = $HTTP_POST_VARS["MSISDN"]; // MSISDN
$s_con = $HTTP_POST_VARS["Content"]; // Content
$s_chn = $HTTP_POST_VARS["Channel"]; // Channel
$s_pay = $HTTP_POST_VARS["DataType"]; // Data Type
$s_dat = $HTTP_POST_VARS["DateReceived"]; // Date Received
$s_cam = $HTTP_POST_VARS["CampaignID"]; // CampaignID
$b_IsValid = getValidateRequest($s_ref, $s_trg, $s_shc, $s_pho, $s_con, $s_cam, $s_chn, $s_pay,
$s_dat);
if ($b_IsValid)
{
$s_ResponseCode = "success";
}
else
{
$s_ResponseCode = "fail";
}
exit($s_ResponseCode);
/*******************************************************************************/
function getValidateRequest ($s_req_ref, $s_req_trg, $s_req_shc, $s_req_pho, $s_req_con, $s_req_cam,
$s_req_chn, $s_req_pay, $s_req_dat) {
/*
* Stub function to be replaced with whatever process is needed to
* process/validate request from server by specific client requirements.
*/
return(true);
}
?>
lastly
<?php
$s_ref = $HTTP_POST_VARS["Reference"]; // Reference
$s_sta = $HTTP_POST_VARS["Status"]; // Status
$s_dat = $HTTP_POST_VARS["DateDelivered"]; // Date Delivered
$b_IsValid = getValidateReceipt($s_ref, $s_sta, $s_dat);
if ($b_IsValid)
{
$s_ResponseCode = "success";
}
else
{
$s_ResponseCode = "fail";
}
exit($s_ResponseCode);
/*******************************************************************************/
function getValidateReceipt ($s_req_ref, $s_req_sta, $s_req_dat)
{
/*
* Stub function to be replaced with whatever process is needed to
* process/validate receipts from server by specific client requirements.
*/
return(true);
}
?>
Thank you very much in advance Regards Greg
© Stack Overflow or respective owner