【问题标题】:Symfony - curl return invalid requestSymfony - curl返回无效请求
【发布时间】:2019-03-09 15:51:57
【问题描述】:

我正在使用具有指定 url 的现金流文档来尝试返回测试请求,但 dump() 返回此错误..

“V|99E5BB5DF59|000|V226|无效请求\n”

控制器必须返回响应(V|99E5BB5DFC6|000|V226|无效请求 给定)。

我的代码..

  // jSON URL which should be requested
    $json_url = 'https://secure.cashflows.com/gateway/remote';

    $username = '5949138';  // authentication
    $password = 'Ad368w9XYw';  // authentication

    // jSON String for request
    $json_string ="auth_id=5949138&auth_pass=Ad368w9XYw&card_num=4000000000000002&card_cvv=123&card_ex
                    piry=0116&cust_name=Testing&cust_address=My%20house%0AMy%20street%0AMy%20Town&cust_post
                    code=CB22%205LD&cust_country=GB&cust_ip=123.45.67.89&cust_email=test@test.com&tran_ref=abc123
                    &tran_amount=9.99&tran_currency=GBP&tran_testmode=0&tran_type=sale&tran_class=ecom";

    // Initializing curl
    $ch = curl_init( $json_url );

    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD,$username . ':' . $password);  // authentication
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json_string));
    curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');

    // Getting results
    $result = curl_exec($ch); // Getting jSON result string

    return new JsonResponse($result);

我不知道是什么导致了问题。

【问题讨论】:

标签: php json symfony curl response


【解决方案1】:

您正在将一个数组传递给 POSTFIELDS

json_encode:

CURLOPT_POSTFIELDS => json_encode($json_string),

Als 检查 Content-Type(大写 T)

【讨论】:

  • 还是一样。当我尝试示例表单文档时,错误是一样的。
猜你喜欢
  • 1970-01-01
  • 2014-08-05
  • 2013-07-17
  • 2020-01-31
  • 2014-09-18
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多