2

I've got two scripts on a windows server, setup to receive data from a post.

One is a PHP file that works.

<?php   
echo "Hello! <br/> This is a Post Back script that writes to a text file!";

// retrieving information from Post Back
$accounting         = $_POST["accountingAmount"];
$accounting_txt     = "accounting: " . "$accounting" . "\n\n";
$address1           = $_POST["address1"];

// LOTS MORE FIELDS //

$address1_txt       = "address1: " . "$address1" . "\n\n";
"$recurPrice_txt" . "$referer_txt" . "$referringUrl_txt" . "$reservationId_txt" . "$responseDigest_txt" . "$start_date_txt" . "$state_txt" . "$sub_id_txt" . "$typId_txt" . "$username_txt" . "$zipcode_txt";

// write to a text file
$myFile = "postback.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $message;
fwrite($fh, $stringData);
fclose($fh);
?>

The ASP.NET MVC script is this:

[HttpPost]
    public ActionResult approved(FormCollection formValues)
    {           
            var context = new LSmixDbEntities();
            PaymentHistory ph = new PaymentHistory();
            StringBuilder s = new StringBuilder();
            foreach (string key in Request.Form.Keys)
            {
                s.AppendLine(key + ": " + Request.Form[key] + Environment.NewLine);
            }
            string formData = s.ToString();
    //save formData in db
    }

I tested by putting vs on the server itself and breakpointing, the action doesn't even start.

Is there any reason a .php file would be hit by a remote postback, but an MVC action wouldn't be?

4

1 回答 1

1

PHP 脚本没有任何 HTTP 方法保护 - 它会在 GET 或 POST 请求中运行,而 MVC 引擎仅approved在响应 POST 请求时触发该方法(因为您具有该[HttpPost]属性)。我猜你只是用你的网络浏览器访问你的服务器(它总是会触发一个 GET 请求),而不是使用一个工具来创建一个 POST 请求。

于 2012-11-27T22:37:33.273 回答