首页 > 解决方案 > 验证 unix cURL 命令

问题描述

我对 cURL 比较陌生。我有一个 cURL 命令将 csv 上传到 API 端点。这是卷曲,

curl 'https://api.myweb.tld/something/upload' \
­-X POST \
­-H 'Authorization: Basic SomeRandomTokenIHaveReceived' \
­-H 'Content­Type: multipart/form­data' \
­-F 'csv=@./the_file.csv' \
­-F 'encoding=windows­1252' \
­-F 'fieldSeparator=,' \
­­-- compressed | json_pp > response.json

它所做的只是将 csv 中的值传递给 API 端点。并在 response.json 中接收响应以了解操作是否成功。

我在 OSX 终端上运行它并在 response.json 文件中得到这个响应

{
   "type" : "APIException",
   "message" : "Method 'GET' not allowed. Allowed methods are: POST,OPTIONS.",
   "identifier" : 70004,
   "statusCode" : 405
}

我还在终端中收到一些警告,如下所示:

curl: (6) Could not resolve host: ­X
curl: (6) Could not resolve host: POST
curl: (6) Could not resolve host: ­H
curl: (3) Port number ended with ' '
curl: (6) Could not resolve host: ­H
curl: (3) Port number ended with ' '
curl: (6) Could not resolve host: ­F
curl: (7) Failed to connect to  port 80: Connection refused
curl: (6) Could not resolve host: ­F
curl: (6) Could not resolve host: encoding=windows­1252
curl: (6) Could not resolve host: ­F
curl: (6) Could not resolve host: fieldSeparator=,
curl: (6) Could not resolve host: ­­compressed

谁能指出它有什么问题?我需要别的东西来执行这个吗?如果我想在 PHP 中运行它,它是如何工作的?我只是不太熟悉 cURL 及其性质,如果有人能给我一些提示,我会很高兴。

谢谢大家!

标签: phpunixcurl

解决方案


推荐阅读