我正在使用此API:https://gatewaydtx1.giact.com/gVerifyV2/POST/Verify.asmx?op=Call在php中使用curl。我可以在對API的單個調用中進行測試。但是,當我嘗試循環多個記錄時,在第一個記錄之後的每次嘗試中都會出現錯誤。在PHP中循環時出現奇怪的API問題
這裏是我的代碼:
<?
//set the variables for posting
$CompanyID = "123";
$Token = "013443234-224e-4f46-bad4-6693deae2231";
$CheckNumber = "1";
$Amount = "30";
$UniqueID = "111";
$url = "https://gatewaydtx1.giact.com/gVerifyV2/POST/Verify.asmx/Call";
//Get the records from table
$sql = "SELECT id,account_no,routing_no FROM banktable WHERE(status = 'queued') LIMIT 0,100";
$result = mysql_query($sql) or die("Error: " . mysql_error() . "<br>");
while($row = mysql_fetch_array($result)) {
$RoutingNumber = $row['routing_no'];
$AccountNumber = $row['account_no'];
//Do the curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $url);
$post_array = array(
"CompanyID"=>$CompanyID,
"Token"=>$Token,
"RoutingNumber"=>$RoutingNumber,
"AccountNumber"=>$AccountNumber,
"CheckNumber"=>$CheckNumber,
"Amount"=>$Amount,
"UniqueID"=>$UniqueID,
);
//url-ify the data
foreach($post_array as $key=>$value){
$post_array_string .= $key.'='.$value.'&';
}
$post_array_string = rtrim($post_array_string,'&');
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_POST,count($post_array));
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_array_string);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
}
?>
這裏就是循環4行這個代碼後輸出:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.giact.com/webservices/gVerifyV2/">33302261|true|No Data|ND00</string>
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
注意,它嘗試的第一個紀錄產生正確的結果。之後,錯誤。即使我在這裏專門提到了我的循環,但我應該注意到,如果我只是在頁面上硬編碼兩個或更多的捲髮,也會發生這種情況。
'// url-ify the data' =>幸運的是,我們有'http_build_query':P其餘的它看起來更像是一個數據問題:如果你隨機播放你的輸入(即跳過第一條記錄,直接第二個):它突然成功了,還是失敗了,就像它被稱爲第二個一樣? – Wrikken
如果他們解決了您的問題,您應該接受問題的答案。 –