我有如下 PHP 代码:
$url = "http://my.parkpay.co.za/includes/api.php"; # URL to WHMCS API file goes here
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["accesskey"] = "4a588e76-4e1c-4240-baad-4d2d6e3433cf";
$postfields["responsetype"] = "json";
$postfields["action"] = "addbillableitem";
$postfields["clientid"] = "3";
$postfields["description"] = "Test From PHP Code";
$postfields["amount"] = "250.00";
$postfields["invoiceaction"] = "nextinvoice";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$jsondata = curl_exec($ch);
if (curl_error($ch)) {
die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
}
curl_close($ch);
和这样的 C# 代码:
public string PostTestBillableItem()
{
const string username = "{username}";
var passwordHash = Md5Hash({passwordHash});
var formFields = new[]
{
new KeyValuePair<string, string>("username", username),
new KeyValuePair<string, string>("password", passwordHash),
new KeyValuePair<string, string>("accesskey", "4a588e76-4e1c-4240-baad-4d2d6e3433cf"),
new KeyValuePair<string, string>("responsetype", "json"),
new KeyValuePair<string, string>("action", "addbillableitem"),
new KeyValuePair<string, string>("clientid", "3"),
new KeyValuePair<string, string>("description", "Payment Towards Web Design Project"),
new KeyValuePair<string, string>("amount", "250.00"),
new KeyValuePair<string, string>("invoiceaction", "nextinvoice")
};
var postData = formFields.Aggregate("", (current, pair) => current + (pair.Key + "=" + HttpUtility.UrlEncode(pair.Value) + "&"));
var client = new WebClient();
var result = client.UploadString("http://my.parkpay.co.za/includes/api.php", postData);
return result;
}
当我在 IIS 7.5 上执行 PHP 代码时,我得到了成功的响应。当我执行看似相同的 C# 代码时,由于我的 IP 地址而被阻止。我使用“accesskey”值是为了防止 IP 地址检查。它适用于 PHP 代码,而不是 C# 代码。
我可以使用哪些工具来检查离开请求 HTTP?在每种情况下发布的表单数据都是相同的,包括密码哈希,所以我想我正在寻找消息中的标题或编码差异。