Recently in on a post on the RESTful ASP.NET Web API framework I used curl to post JSON to an HTTP endpoint:

最近在RESTful ASP.NET Web API框架上的一篇文章中,我使用curl将JSON发布到HTTP端点:

curl -X POST -H "Content-Type: application/json" -d "{ Name: 'Scott Guthrie', Age: 67}"

Curl is lovely and should be in your c:\utils folder and more importantly in your PATH. I have a UTILS folder in my Dropbox and in the PATH on all my machines. Whenever I find a useful no-install utility I put it in there.

Curl很可爱,应该位于c:\ utils文件夹中,更重要的是位于PATH中。 我的Dropbox和所有机器上的PATH中都有一个UTILS文件夹。 每当我找到有用的免安装实用程序时,就会将其放在其中。

Curl is great but it's still confusing enough to me that I don't use it enough. It's slightly obscure command-line switches are keeping me from using it on a regular basis.

Curl很棒,但是它仍然让我感到困惑,以至于我使用得还不够。 命令行开关有点晦涩难懂,这使我无法定期使用它。

For HTTP work there is a better utility called HTTPie at http://httpie.org. (It has nothing to do with IE (Internet Explorer)). For Mac and Linux folks who use Python all the time, it's easy to install, you just

对于HTTP工作, http: //httpie.org上有一个更好的实用程序,称为HTTPie。 (与IE(Internet Explorer)无关。) 对于一直使用Python的Mac和Linux人士,安装简便,您只需

pip install -U httpie

For Windows folks who don't use Python it's a little harder to install, but it's worth it and I recommend you take a moment and set it up. You'll wonder how you lived without it.

对于不使用Python的Windows人士来说,安装起来有点困难,但这是值得的,我建议您花点时间进行设置。 您会想知道没有它的生活。

安装HTTPIE (Installation of HTTPIE)

First, go download Python. I got the x86 version of Python 3.2.3 cause it was the latest and I didn't think I needed the x64 one.

首先,下载Python 。 我获得了x86版本的Python 3.2.3,因为它是最新版本,我认为我不需要x64版本。

I then added c:\python32 and c:\python32\scripts to my path. I do this by hitting WinKey+Break, then Advanced, then Environment.

然后,我在路径中添加了c:\ python32和c:\ python32 \ scripts。 我通过点击WinKey + Break,然后选择Advanced,再选择Environment。

Second, download CURL. Yes, I realize the irony, but it's still a VERY useful tool. I downloaded the 7.27 binary SSL Win32 version, unblocked it, unzipped it and put it in C:\UTILS so it was automatically in my PATH.

其次,下载CURL 。 是的,我意识到这一点很讽刺,但是它仍然是非常有用的工具。 我下载了7.27二进制SSL Win32版本,将其解除阻止,解压缩并将其放在C:\ UTILS中,以便它自动出现在我的PATH中。

Third, run this from an Administrator command prompt. Note again that it needs both curl.exe and python.exe in the PATH to run as it is. This should run without incident.

第三,从管理员命令提示符运行。 再次注意,它需要PATH中的curl.exe和python.exe才能按原样运行。 这应该没有问题地运行。

curl http://python-distribute.org/distribute_setup.py | python

Then run

然后跑

curl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

This should end with "successfully installed pip."

这应该以“成功安装pip”结尾。

Pip is a Python package manager.

Pip是Python软件包管理器。

Finally, run

最后跑

pip install -U https://github.com/jkbr/httpie/tarball/master

I'm recommending you install the development edge build of HTTPie rather than just "pip install httpie" as the developer is actively fixing Windows issues and just recently helped me with one.

我建议您安装HTTPie的开发边缘版本,而不仅仅是“ pip install httpie”,因为开发人员正在积极解决Windows问题,最近才帮助我解决了一个问题。

So, to sum up what you need to run, in four lines, assuming curl.exe, python.exe and python scripts are all in your PATH.

因此,总结一下您需要运行的内容,假设curl.exe,python.exe和python脚本都在PATH中,则分四行显示。

curl http://python-distribute.org/distribute_setup.py | pythoncurl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | pythoncurl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | pythonpip install -U https://github.com/jkbr/httpie/tarball/master

运行HTTPie (Running HTTPie)

You'll know it works if you can run "http" from the command line and get this output:

如果您可以从命令行运行“ http”并获取以下输出,您就会知道它有效:

C:\Users\scottha\Desktop> httpusage: http-script.py [--help] [--version] [--json | --form] [--output FILE]                      [--pretty | --colors | --format | --ugly]                      [--print OUTPUT_OPTIONS | --verbose | --headers | --body]                      [--style STYLE] [--stream] [--check-status]                      [--auth USER:PASS] [--auth-type {basic,digest}]                      [--verify VERIFY] [--proxy PROXY] [--allow-redirects]                      [--timeout SECONDS] [--traceback] [--debug]                      [METHOD] URL [ITEM [ITEM ...]]http-script.py: error: too few arguments

Here's where the fun happens. The syntax is VERY intuitive. Here I post some JSON to an endpoint that will echo it back.

这就是乐趣发生的地方。 语法非常直观。 在这里,我将一些JSON发布到将回显它的终结点。

C:\> http POST http://localhost:50231/api/Contact name=scott age:=100HTTP/1.1 200 OKContent-Length: 26Content-Type: application/json; charset=utf-8Date: Fri, 17 Aug 2012 21:59:51 GMTServer: Microsoft-HTTPAPI/2.0

{    "age": 100,    "name": "scott"}

It's just like using HTTP itself, except from the command line. The best part is that it will take name=value for strings and name:=value for non-strings and turn it into JSON!

就像从命令行使用HTTP本身一样。 最好的部分是它将对字符串使用name = value,对于非字符串将使用name:= value并将其转换为JSON!

HTTPie supports any HTTP Verb, FORM data, raw JSON, and lots of other features. Here's another example:

HTTPie支持任何HTTP Verb,FORM数据,原始JSON和许多其他功能。 这是另一个例子:

C:\>http PUT api.example.com/person/1 name=John age:=29 married:=false hobbies:='["http", "pies"]'PUT /person/1 HTTP/1.1Accept: application/jsonContent-Type: application/json; charset=utf-8Host: api.example.comUser-Agent: HTTPie/0.2.7dev

{    "age": 29,    "hobbies": [        "http",        "pies"    ],    "married": false,    "name": "John"}

There's lots more examples here https://github.com/jkbr/httpie/ and I encourage you to check it out. I'll leave you with a lovely PowerShell screenshot showing that HTTPie also does syntax highlighting at the command line!

https://github.com/jkbr/httpie/上有更多示例,我鼓励您检查一下。 我将为您提供一个可爱的PowerShell屏幕截图,该屏幕截图显示HTTPie还在命令行中突出显示了语法!

Awesome. Expect to see this tool in all my Web API and JSON demos. Go get it and star it at GitHub.

太棒了希望在我所有的Web API和JSON演示中都能看到此工具。 去获取它并在GitHub上加注星标。

翻译自: https://www.hanselman.com/blog/installing-httpie-http-for-humans-on-windows-great-for-aspnet-web-api-and-restful-json-services

在Windows上安装HTTPIE(人类HTTP)-非常适合ASP.NET Web API和RESTful JSON服务相关推荐

  1. 为了在 Windows 上安装 GCC

    写在源文件中的源代码是人类可读的源.它需要"编译",转为机器语言,这样 CPU 可以按给定指令执行程序.C 语言编译器用于把源代码编译成最终的可执行程序.这里假设您已经对编程语言编 ...

  2. 安装oracle后在cmd,在WINDOWS上安装ORACLE RAC的注意事项

    在WINDOWS上安装ORACLE RAC的注意事项 1.检查防火墙和杀毒软件 如果不关掉防火墙,在安装CRS时,在"Oracle Clusterware Configuration Ass ...

  3. Windows上安装AD域控制器注意事项及常见问题处理办法

    以Windows Server 2008 R2 SP1 x64为例,在ECS Windows上安装域控制器时,要注意的事项和常见问题说明如下: 1. 要点和注意事项: 所有域节点的如下服务必须启动,推 ...

  4. Git学习系列之Windows上安装Git之后的一些配置(图文详解)

    不多说,直接上干货! 前面博客 Git学习系列之Windows上安装Git详细步骤(图文详解) 第一次使用Git时,需要对Git进行一些配置,以方便使用Git. 不过,这种配置工作只需要进行一次便可, ...

  5. python 调用 tensorflow.dll_解决windows上安装tensorflow时报错,“DLL load failed: 找不到指定的模块”的问题...

    最近打算开始研究一下机器学习,今天在windows上装tensorflow花了点功夫,其实前面的步骤不难,只要依次装好python3.5,numpy,tensorflow就行了,有一点要注意的是目前只 ...

  6. windows上安装Anaconda和python的教程详解

    一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...

  7. PHP 1:在Windows上安装和配置PHP,Apache和My SQL

    PHP 1:在Windows上安装和配置PHP,Apache和My SQL 原文:PHP 1:在Windows上安装和配置PHP,Apache和My SQL 如果你Google一把类似的主题,你会发现 ...

  8. java 中window_教你如何在windows上安装Java

    最近够倒霉的,电脑硬盘坏了,重新做了个系统,各种环境全都没了,/(ㄒoㄒ)/~~ 然后我发现自己在重新安装各种环境的时候,有些东西竟然还需要去查,所以决定把这些环境的配置都写成博客记录下来. 今天就教 ...

  9. Windows上安装JDK

    Windows上安装JDK Windows上安装JDK 题外话 什么是JDK JRE 和 JDK 的区别是什么? 下载JDK并安装 设置环境变量 新建 JAVA_HOME 新建 CLASSPATH 编 ...

最新文章

  1. CUDA之nvidia-smi命令详解---gpu
  2. 通过IP地址和子网掩码计算相关地址
  3. maven编译不通过:软件包com.sun.org.apache.xml.internal.security.utils.Base64 不存在
  4. windows安装ruby on rails
  5. 微课|Python三种方法统计各分数段内的人数(17分钟)
  6. Ajax与Comet
  7. 华为secoclient提示“无法建立vpn链接,vpn服务器可能无法到达”
  8. Thor 1.3.4免费安装
  9. 备战数学建模14-熵权法确定指标权重系数
  10. springmvc/ssm框架详细图文解说流程图及运行原理_附源码
  11. 探究文华盘整(PANZHENG)函数之一
  12. java星号心形代码_c语言实现星号爱心的代码
  13. unity3d 700种 材质球_活动策划:这10种气球创意玩法,让活动现场的布置更高级。...
  14. vue2的 watch的理解(7)
  15. 5年市值蒸发2000多亿 绿地控股二次混改能否迎来春天?
  16. bootstrap3 表单构建器_Knex - 灵活轻便的 Node.js SQL 查询构建器
  17. 实验三十六 Windows Server 2012 RDS桌面虚拟化之七VDI虚拟桌面的更新和维护
  18. matlab构造差商表,牛顿法 代数插值 – 差商表的求法
  19. 信安软考 第十二章 网络安全审计技术
  20. 监督分类:SVM即支持向量机实现遥感影像监督分类(更新:添加机器学习模型存储、大影像划框拼接)

热门文章

  1. oracle建表加compress,oracle 建表后添加表注释及字段注释
  2. Hadoop之父祝贺黄色小象十岁生日快乐
  3. Words for Games
  4. pytorch中的二分类及多分类交叉熵损失函数
  5. 基于串口调试助手的WIFI模块调试-FPGA简单联网(点灯)
  6. 主机管理+堡垒机系统开发
  7. [Datawhale-李宏毅机器学习-39期]-001-机器学习介绍
  8. javaweb设计简易计算器
  9. 20230209 Python的列表及相关操作
  10. 企业使用CRM客户关系管理系统的四大理由