You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP Curl脚本提交请求时遇Access Denied问题求助

解决PHP Curl请求被Access Denied的问题

以下是针对你的Curl脚本的具体修复建议:

1. 修复POST数据与Content-Type不匹配的核心问题

你当前的POST数据是JSON格式,但Content-Type设置为application/x-www-form-urlencoded,这会导致服务器无法正确解析请求,同时可能触发拦截规则。另外你的JSON存在语法错误:

  • ssl_amount字段末尾多了一个双引号
  • ssl_address2字段的字符串未闭合
  • 错误使用"转义引号(PHP中直接用\"或单引号包裹JSON即可)

修正后的代码片段:

// 修正后的JSON数据
$postData = '{
    "fields": {
        "ssl_transaction_type": "ccverify",
        "ssl_salestax": "0",
        "ssl_first_name": "MAR",
        "ssl_last_name": "KO",
        "ssl_company": "SADA",
        "ssl_avs_address": "11 3rd St",
        "ssl_address2": "APT, SUITE, BLDG. (OPTIONAL...)",
        "ssl_city": "Newark",
        "ssl_state": "NJ",
        "ssl_avs_zip": "07107",
        "ssl_country": "USA",
        "ssl_email": "deoei6@gmail.com",
        "ssl_phone": "2342424243",
        "ssl_invoice_number": 100254,
        "ssl_amount": 15
    }
}';

// 调整Content-Type为JSON格式
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charset=UTF-8',
    'Host: www.convergepay.com',
    'Origin: https://classicappreciation.com/',
    'Referer: https://classicappreciation.com/',
    'Accept: application/json, text/javascript, */*; q=0.01',
    'Accept-Language: en-US,en;q=0.9',
    'X-Requested-With: XMLHttpRequest'
));

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

2. 恢复SSL验证(禁用验证易被拦截)

禁用CURLOPT_SSL_VERIFYPEER和CURLOPT_SSL_VERIFYHOST不仅不安全,还可能被服务器识别为异常请求,建议开启验证:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// 若遇到证书信任问题,可指定CA证书路径
// curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');

3. 完善User-Agent和请求头

确保User-Agent使用真实浏览器标识,避免空值或异常标识:

$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

同时补充浏览器默认发送的Accept、Accept-Language等头,减少被拦截概率。

4. 模拟完整会话流程

很多网站会验证会话Cookie,需先访问来源页面获取有效Cookie,再提交支付请求:

// 第一步:访问来源页面获取Cookie
$ch = curl_init('https://classicappreciation.com/');
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
curl_exec($ch);
curl_close($ch);

// 第二步:发起支付请求,复用Cookie
$ch = curl_init('https://www.convergepay.com/hosted-payments/service/payment/hpe/process');
// 其他Curl配置...
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
$card = curl_exec($ch);

5. 补充其他关键配置

  • 显式指定POST请求方法:curl_setopt($ch, CURLOPT_POST, 1);
  • 启用压缩支持:curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

内容的提问来源于stack exchange,提问作者vicky beterse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 23:17:18