簡體   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