My problem:

Running windows 7 and using the executable command line tool to curl my localhost server api for POST data was returning me an error that seems to be really common.

The request was being sent properly with the exception that the data was not reaching the server as it should causing my REST service to insert data with null values.

What seems to be causing the error: imagine something like this

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

Result of the returning data

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

After some searching i figured out that problem couldn't be the sintax used for the request since it works on UNIX shells.

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

I tried to work around with those " escaping it \" but it still didn't work

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

So i gave up. Windows seems to messing up with the JSON object sent on POST

asked Aug 6 '12 at 19:01
Lothre1

94621529
 
    
Please do not add [solved] to your question title. If you've figured out the answer to your question, you should post it as an answer. – Cody Gray Aug 6 '12 at 23:20
1  
Thank you for the warning @CodyGray. I'll correct my Post. – Lothre1 Aug 6 '12 at 23:35

5 Answers

I ran into the same issue on my win7 x64 laptop and was able to get it working using the curl release that is labeled Win64 - Generic w SSL by using the very similar command line format:

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

Which only differs from your 2nd escape version by using double-quotes around the escaped ones and the header parameter value. Definitely prefer the linux shell syntax more.

cURL POST command line on WINDOWS RESTful service的更多相关文章

  1. Cookies with curl the command line tool

    w https://curl.haxx.se/docs/http-cookies.html curl has a full cookie "engine" built in. If ...

  2. [转]How do I run msbuild from the command line using Windows SDK 7.1?

    本文转自:http://stackoverflow.com/questions/6319274/how-do-i-run-msbuild-from-the-command-line-using-win ...

  3. How to install IIS 7.5 on Windows 7 using the Command Line

    原文 How to install IIS 7.5 on Windows 7 using the Command Line On Windows Vista, to install IIS 7.0 f ...

  4. Create Windows Server 2008 cluster from the command line

    How to create a Windows Server 2008 cluster from the command line? Creating a cluster in Server 2008 ...

  5. [Windows]远程管理服务WinRM远程管理Windows服务器 Invalid use of command line. Type "winrm -?" for help.

    运行环境 Windows 2012 R2 1. Windows需要打开WinRM服务,Server系统默认打开,默认端口5985 # WinRM服务查看 PS C:\Users\Administrat ...

  6. MySQL 5.7 Command Line Client输入密码后闪退和windows下mysql忘记root密码的解决办法

    MySQL 5.7 Command Line Client输入密码后闪退的问题: 问题分析: 1.查看mysql command line client默认执行的一些参数.方法:开始->所有程序 ...

  7. windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help

    windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help 在windows8操作系统上安装 ...

  8. [RabbitMQ]Windows环境下rabbitmqclt(Command Line Tools)出现Erlang distribution failed错误的解决方法

    摘要 当使用rabbitmqctl时出现Erlang distribution failed,把%SystemRoot%Windows\System32\config\systemprofile下的. ...

  9. 如何在Windows下开发Python:在cmd下运行Python脚本+如何使用Python Shell(command line模式和GUI模式)+如何使用Python IDE

    http://www.crifan.com/how_to_do_python_development_under_windows_environment/ 本文目的 希望对于,如何在Windows下, ...

随机推荐

  1. git第一次提交代码到远程仓库

    博客搬家了,本文新地址:http://www.zicheng.net/article/4 感谢支持 本操作说明是先有代码,后来创建git仓库,然后把本地代码提交到远程仓库的操作步骤: 1.初始化 在当 ...

  2. 通过PowerShell获取TCP响应(类Telnet)

    通常情况下,为了检测指定的TCP端口是否存活,我们都是通过telnet指定的端口看是否有响应来确定,然而默认情况下win8以后的系统默认是不安装telnet的.设想一下如果你黑进了一个服务器,上面没装 ...

  3. 结合使用saiku、mondrian workbentch建立多维查询报表

    1.简介 前几篇博客已经介绍了saiku.mondrian.MDX和模式文件他们之间的关系,那么如何将它们串联起来,供产品人员使用哪?下面咱们一步一步的实现 2.建立数据表 建表语句参考:http:/ ...

  4. mac 自动配置java版本

    首先输入命令:vi .bash_profile ,添加如下内容: # Mac默认 JDK (Mac默认自带了一个jdk6版本) export JAVA_6_HOME=`/usr/libexec/jav ...

  5. windows下配置启动多个mysql服务

    查找配置做下记录 先安装mysql5.6,安装不在介绍 接下来配置启动另一个mysql服务, 1:先到服务里停止在运行的mysql服务 2:到mysql的安装目录下(默认安装目录在c:\Program ...

  6. PLSQL Developer 出64位版了

    在win64环境上,一般安装oracle客户端都是64位的了,Toad 也是64位的,但是PLSQL Developer 还是32位的,只能单单为它装一个32位的oracle 客户端,现在退出64位, ...

  7. 在Visual Studio 2010中进行“项目重命名”的有效工具

    地址:http://www.cnblogs.com/dudu/archive/2011/12/11/visual_studio_2010_project_rename.html 提示:这个工具一次 r ...

  8. 后端码农谈前端(HTML篇)第二课:常见元素

    一.根元素 <doctype> 定义文档类型. <html> 定义 HTML 文档. 二.元数据元素 <head> 定义关于文档的信息. <meta> ...

  9. DDD:谈谈数据模型、领域模型、视图模型和命令模型

    背景 一个类型可以充当多个角色,这个角色可以是显式的(实现了某个接口或基类),也可以是隐式的(承担的具体职责和上下文决定),本文就讨论四个角色:数据模型.领域模型.视图模型和命令模型. 四个角色 数据 ...

  10. Tips7:Unity中 Scene视图 和 Game视图 中 视角(Camera)的控制

    选中你要改变的相机,然后点击GameObject-->Align With View 选项(快捷键Ctrl+Shift+F)使相机视角和当前Sence视图中一样 通过这样可以控制在Game视图( ...