在 CURL 中打开查询字符串文件时收到错误请求

发布于 2024-10-06 08:55:21 字数 1350 浏览 1 评论 0原文

$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB 

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post to 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
    curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns 
    curl_setopt($ch, CURLOPT_FAILONERROR, 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $result = curl_exec($ch); // run the whole process 

    print_r($result); 

    curl_close($ch); 

我还使用了 file_get_conent 和 fopen 但都返回了 BAD REQUEST 错误, 请帮助我了解

更多详细信息,请参阅下面的链接

http://www.uqwibble.com /Phase-2/ach.php

$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB 

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post to 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
    curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns 
    curl_setopt($ch, CURLOPT_FAILONERROR, 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $result = curl_exec($ch); // run the whole process 

    print_r($result); 

    curl_close($ch); 

i also used file_get_conent and fopen but all are returning me BAD REQUEST error,
please help me out

for more detail please see the link below

http://www.uqwibble.com/Phase-2/ach.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

预谋 2024-10-13 08:55:21

假设您发布的代码是准确的,那么这一行就是问题所在:

$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB

这里看起来您尝试定义 $URL 但当您将它与 cURL 一起使用时,您正在引用 $url。变量区分大小写。其次,您的 $URL: 无效,您想要使用 $url =

另外,我会像这样对参数进行编码:

$baseurl = 'https://demo.firstach.com/https/TransRequest.asp';
$params = array(
 'Login_ID' =>  'someit',
 'Transaction_Key' => 'somekey',
 'Customer_ID'= => 23,
 'Customer_Name' => 'Muhammad Naeem',
 'Customer_Address' => 'Address',
 'Customer_City' => 'city',
 'Customer_State' => 'HI',
 'Customer_Zip' => '54000',
 'Customer_Phone' => '--',
 'Customer_Bank_ID' => '111111118'
 'Customer_Bank_Account' => '12345678901234567890'
 'Account_Type' => 'Business Checking'
 'Transaction_Type' => 'Debit'
 'Frequency' => 'Once'
 'Number_of_Payments' => 1,
 'Effective_Date'=> '12/05/2010',
 'Amount_per_Transaction' => '10.00',
 'Check_No'=> '',
 'Memo'=> '',
 'SECCType' => 'WEB'
);

$url = sprintf('%s?%s', $baseurl, http_build_query($params));

这样 http_build_query 将处理您所有的 url 编码,并且您可以事先使用数组,以便轻松查看正在发生的情况并添加/删除/更改参数。或者,如果它是一个发布请求,您可以使用:

curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

它将处理所有参数编码以及不直接从数组中获取的参数,这样他们就不需要手动附加到$url

Well assumign the code you posted is accurate then this line is the issue:

$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB

here it looks liek you attemtp to define $URL but when you use it with cURL you are referencing $url. The varibales are case sensitive. Secondly you have $URL: which is not valid you want to use $url =.

Addiitonally i would encode the params like this:

$baseurl = 'https://demo.firstach.com/https/TransRequest.asp';
$params = array(
 'Login_ID' =>  'someit',
 'Transaction_Key' => 'somekey',
 'Customer_ID'= => 23,
 'Customer_Name' => 'Muhammad Naeem',
 'Customer_Address' => 'Address',
 'Customer_City' => 'city',
 'Customer_State' => 'HI',
 'Customer_Zip' => '54000',
 'Customer_Phone' => '--',
 'Customer_Bank_ID' => '111111118'
 'Customer_Bank_Account' => '12345678901234567890'
 'Account_Type' => 'Business Checking'
 'Transaction_Type' => 'Debit'
 'Frequency' => 'Once'
 'Number_of_Payments' => 1,
 'Effective_Date'=> '12/05/2010',
 'Amount_per_Transaction' => '10.00',
 'Check_No'=> '',
 'Memo'=> '',
 'SECCType' => 'WEB'
);

$url = sprintf('%s?%s', $baseurl, http_build_query($params));

That way http_build_query will take care of all your url encoding and you can work with an array before hand so its easy to see whats going on and add/remove/change paramters. Alternatively if its a post request you could jsut use:

curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

which will take care of all the parameter encoding and what not directly from the array this way they dont need to be appended manually to the $url.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文