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



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

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

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

您可以尝试从服务器上进行基本的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'

您可以尝试使用和不使用显式标头,看看这是否有区别。

最后我找到了一个解决方法,我将把它贴在这里,以防将来有任何参考。我咨询了Stripe的技术支持,他们的回答给了我一个想法。

Stripe的支持发现的原因/问题:请求正在发送一个空的Content-Type报头。

我已经通过库,并尝试调试什么请求头被发送出去,但发现实际上在日志中它只是"授权"头默认情况下,不知道如何添加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();

最新更新