繁体   English   中英

Laravel Omnipay/Stripe 无法在 linux 上发送请求

[英]Laravel Omnipay/Stripe unable to send request on linux

目前我已经将omnipay/stripe集成到我的laravel项目中,在我的本地还可以,但是当我在服务器上测试它时它返回“无效请求:不支持的内容类型。如果错误仍然存在并且您需要帮助,请联系支持@条纹.com。” 尝试发送请求时,请提供帮助。

$response = $gateway->purchase([
'amount' => $amount,
'currency' => $currency,
'token' => $token,
'confirm' => true,
'description' => auth()->user()->name
])->send();

错误Content-Type. 表示请求的Content-Typeheader(该值包含在句点之前)。 虽然我无法解释为什么会发生这种情况,但有些东西干扰了请求。

您可以尝试从您的服务器进行基本的curl调用(如下所示),以帮助隔离这是网络级干扰还是应用程序堆栈中的干扰。

curl --request POST \
  --url 'https://api.stripe.com/v1/customers' \
  -u sk_test_123: \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data 'description=test cust'

您可以尝试使用和不使用显式 header 看看这是否有所不同。

最后我找到了一个解决方法,我会在这里发布以防将来参考。 我咨询了 Stripe 的技术支持,他们的回复给了我一个想法。

Stripe 支持发现的原因/问题:发送请求时的 Content-Type 为空 header。

我已经浏览了库并尝试调试正在发送的请求 header 但实际上在日志中发现它只是默认的“授权”header,不知道如何添加 Content-Type,所以根据他们的回应,我在sendData($data)处将'Content-Type' => 'application/x-www-form-urlencoded'添加到omnipay/stripe/src/Message/AbstractRequest.php中。 当然,您也可以以比我更结构化的方式放置它。

令人惊讶的是它有效!

他们还建议了一种您也可以尝试的方法,但我没有。

$request = $gateway->purchase([
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'amount' => $amount,
'currency' => $currency,
'token' => $token,
'confirm' => true,
'description' => auth()->user()->name
])->send();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM