cURL - 在给定范围'start'中找到无效字符 - 'stop'

时间:2013-08-22 17:56:15

标签: api http rest curl

我正在进行一次安静的api通话,但我收到了一个错误。

Warning: Invalid character is found in given range. A specified range MUST 
Warning: have only digits in 'start'-'stop'. The server's response to this 
Warning: request is uncertain.
HTTP/1.1 200 OK
Date: Thu, 22 Aug 2013 17:43:19 GMT
Server: Apache
Content-Length: 208
Allow: GET, HEAD, POST
Vary: Authorization
Content-Type: application/json

在有关无效字符之前,是否有人看到此警告错误?我该如何解决?

我在打电话:

curl https://my/url/for/api --include -H "Content-Type:application/json" -request POST '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' -u user:pass

更多信息:

返回结束时的额外回复

curl: (6) Could not resolve host: POST; nodename nor servname provided, or not known

curl: (3) [globbing] nested braces not supported at pos 33

3 个答案:

答案 0 :(得分:1)

cURL对命令中的方括号感到困惑。它将它们解释为应该处理的一系列字符。无论哪种方式,你的问题都可能在SuperUser上比在Stackoverflow上更合适。

答案 1 :(得分:1)

更正后的命令行可能类似于:

curl https://my/url/for/api \
--include \
-H "Content-Type:application/json" \
-d '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' \
-u user:pass

(为了便于阅读,我将其拆分为多行。)我所做的更改:

1 - - request需要两个破折号,但是因为你设置了POST,它是多余的,我把它删除了

2 - 使用-d(或--data)指定要POST的内容。 --request只接受一个方法字符串 您可以在HTTP请求中替换 POST,但我认为您不希望这样。

答案 2 :(得分:1)

我有类似的情况 - 我的curl请求基本上正在运行,并返回我需要的信息,但有警告,使用以下代码:

curl -request http://...

原来是-request参数,我输错了。它要么像:

curl --request GET http://...

或根本就没有(因为GET是默认值):

curl http://...