簡體   English   中英

(PHP)Ixudra / Curl無法發布文件

[英](PHP) Ixudra/Curl cannot post file

我在laravel項目中使用Ixudra / Curl。 嘗試將文件上傳到Java API時遇到問題。 使用Curl Using命令行可以使用以下工作文件:

curl -X POST \
http://<<api url>>' \
-H 'Content-Type: multipart/form-data' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=xxxxx\
-F 'data={"tables" : ... (no need to post all data)' \
-F 'file=@C:\Users\UserName\Downloads\Test.xls'

使用PHP代碼,我嘗試失敗了:

Curl::to('<<api url>>')
     ->withContentType('multipart/form-data; boundary=' . hash('sha256', uniqid('', true)))
     ->withData(array('data' => {"tables" : ...  ))
     ->withFile('file', 'C:\Users\UserName\Downloads\Test.xls', 'application/vnd.ms-excel', 'Test.xls')
     ->post();

我收到此代碼的響應是:

“ exception”:“ org.springframework.web.multipart.support.MissingServletRequestPartException”,“ message”:“所需的請求部分'file'不存在”

任何想法? 謝謝你的時間

問題已解決,似乎該庫不喜歡我指定內容類型。 刪除該行后,一切正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM