简体   繁体   English

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

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

currently I have integrated omnipay/stripe to my laravel project, it was ok on my local, but when I test it on server then it returned "Invalid request: unsupported Content-Type. If error persists and you need assistance, please contact support@stripe.com."目前我已经将omnipay/stripe集成到我的laravel项目中,在我的本地还可以,但是当我在服务器上测试它时它返回“无效请求:不支持的内容类型。如果错误仍然存在并且您需要帮助,请联系支持@条纹.com。” when trying to send the request, please help.尝试发送请求时,请提供帮助。

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

The exact text of the error Content-Type.错误Content-Type. indicates the request has an empty Content-Type header (the value is included before the period).表示请求的Content-Typeheader(该值包含在句点之前)。 While I cannot explain why this is happening, something is interfering with the request.虽然我无法解释为什么会发生这种情况,但有些东西干扰了请求。

You can try making basic curl calls (like the below) from your server to help isolate whether this is network-level interference or in the application stack.您可以尝试从您的服务器进行基本的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'

You can try with and without the explicit header to see if this make a difference.您可以尝试使用和不使用显式 header 看看这是否有所不同。

Finally I found a workaround, I will post it here incase any future reference.最后我找到了一个解决方法,我会在这里发布以防将来参考。 I have consulted the Stripe's technical support and their respond gave me an idea.我咨询了 Stripe 的技术支持,他们的回复给了我一个想法。

The causes/issue found by Stripe's support: The request is being sent with an empty Content-Type header. Stripe 支持发现的原因/问题:发送请求时的 Content-Type 为空 header。

I have gone through the library and try to debug what the request header was being send out but found out actually in the log it was only the "Authorization" header as default, have no idea on how the Content-Type is added in, so based on their respond, I added in 'Content-Type' => 'application/x-www-form-urlencoded' to omnipay/stripe/src/Message/AbstractRequest.php at sendData($data) .我已经浏览了库并尝试调试正在发送的请求 header 但实际上在日志中发现它只是默认的“授权”header,不知道如何添加 Content-Type,所以根据他们的回应,我在sendData($data)处将'Content-Type' => 'application/x-www-form-urlencoded'添加到omnipay/stripe/src/Message/AbstractRequest.php中。 Of course you could also placed it in the more structured way than I did.当然,您也可以以比我更结构化的方式放置它。

Surprisingly it works !令人惊讶的是它有效!

And they have also suggested one of the way you could try it as well, but I didn't.他们还建议了一种您也可以尝试的方法,但我没有。

$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