【发布时间】:2018-10-29 11:54:30
【问题描述】:
我在我的 laravel 项目中使用 Ixudra/Curl。 当我尝试将文件上传到 Java API 时遇到问题。 使用 Curl 使用命令行正在使用以下文件:
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":"所需的请求部分'文件'不存在"
有什么想法吗?感谢您的宝贵时间
【问题讨论】:
-
我没有使用过这个包,但你可以尝试使用
guzzle/http。我认为它应该可以解决您的问题