gpt4 book ai didi

windows - WINDOWS RESTful 服务上的 cURL POST 命令行

转载 作者:可可西里 更新时间:2023-11-01 11:55:42 26 4
gpt4 key购买 nike

我的问题:使用命令行工具来 curl 我的本地主机服务器,同时发送一些数据和我的 POST 请求不起作用。

似乎是什么导致了错误:想象一下这样的事情

  1. curl -i -X POST -H 'Content-Type: application/json' -d '{"data1": "data goes here", "data2": "data2 goes here"}' http: localhost/path/to/api

返回数据结果

curl: (6) Could not resolve host: application; No data record of requested type
curl: (6) Could not resolve host: data goes here,; No data record of requested type
curl: (6) Could not resolve host: data2; No data record of requested type
curl: (3) [globbing] unmatched close brace/bracket at pos 16

经过一番搜索后,我发现问题不可能是用于请求的语法,因为它适用于 UNIX shell。

Are you possibly using Windows? That so looks like a completely broken shell that doesn't properly deal with single-quotes vs double-quotes. I just tried that command line and it worked fine on my linux box. http://curl.haxx.se/mail/archive-2011-03/0066.html

我试图解决那些“逃避它”的问题,但它仍然没有用

2.

curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data goes here\", \"data2\": \"data2 goes here\"}' http: //localhost/path/to/api

3.

curl -i -X POST -H 'Content-Type: application/json' -d '{\"data1\": \"data goes here\", \"data2\": \"data2 goes here\"}' http: //localhost/path/to/api

所以我放弃了。Windows 似乎搞乱了 POST 上发送的 JSON 对象

最佳答案

我在我的 win7 x64 笔记本电脑上遇到了同样的问题,并且能够使用标记为 Win64 - Generic w SSL 的 curl 版本让它工作。通过使用非常相似的命令行格式:

C:\Projects\curl-7.23.1-win64-ssl-sspi>curl -H "Content-Type: application/json" -X POST http://localhost/someapi -d "{\"Name\":\"Test Value\"}"

它与您的第二个转义版本的唯一区别在于在转义版本和 header 参数值周围使用双引号。绝对更喜欢 linux shell 语法。

关于windows - WINDOWS RESTful 服务上的 cURL POST 命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11834238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com