HTTP Prompt – 交互式命令行HTTP客户端

  • HTTP Prompt – 交互式命令行HTTP客户端已关闭评论
  • 72 views
  • A+
所属分类:存储应用

是基于HTTPie和prompt_toolkit构建的交互式命令行HTTP客户端,具有自动完成和语法突出显示功能。它还支持自动cookie,OpenAPI / Swagger集成以及类Unix管道和输出重定向。此外,它还提供了20多个主题,您可以使用它们。

HTTP Prompt – 交互式命令行HTTP客户端

在本文中,我们将解释如何在Linux中安装和简要使用HTTP-prompt。

Linux中安装HTTP-prompt

使用PIP命令安装HTTP-prompt,就像常规Python包一样,如图所示

$ pip install http-prompt

注意:安装之前先看看你pip的版本,http-prompt要求的版本在19.0.3以及以上,不然会报错,如下:

You are using pip version 8.1.2, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

如果是低版本的话,直接升级,命令如下:

pip install --upgrade pip

您可以使用--user选项将软件包安装到用户主目录中,如下所示:

$ pip install --user http-prompt

要升级http-prompt,请执行以下操作:

$ pip install -U http-prompt

如何在Linux中使用HTTP Prompt

启动方式如下:

Start with the last session or http://localhost:8000
$ http-prompt

Start with the given URL
$ http-prompt http://localhost:3000

Start with some initial options
$ http-prompt localhost:3000/api --auth user:pass username=somebody
要启动会话,只需运行http-prompt命令,如下:
[root@xubo ~]# http-prompt 
Version: 1.0.0
http://localhost:8000>

启动会话后,您可以交互式键入命令,如以下屏幕截图所示。

HTTP Prompt – 交互式命令行HTTP客户端

要查看http-prompt将如何调用HTTPie,请运行以下命令。

> httpie post
如下:
root@xubo ~]# http-prompt 
Version: 1.0.0
http://localhost:8000> httpie post
http POST http://localhost:8000
http://localhost:8000>

您可以发送HTTP请求,输入一个HTTP方法,参数如下:

> head
> get
> post
> put
> patch
> delete

 

实例:

[root@xubo ~]# http-prompt http://www.baiked.com 
Version: 1.0.0
http://www.baiked.com> get
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 185
Content-Type: text/html
Date: Sun, 14 Apr 2019 14:51:43 GMT
Location: https://www.baiked.com/
Server: nginx/1.12.2

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>

http://www.baiked.com> post
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 185
Content-Type: text/html
Date: Sun, 14 Apr 2019 14:52:06 GMT
Location: https://www.baiked.com/
Server: nginx/1.12.2

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>

http://www.baiked.com>

 

可以添加header,查询字符串或正文参数,使用HTTPie中的语法。这里有些例子:

# set header
> Content-Type:application/json

# querystring parameter
> page==5

# body parameters
> username=tecmint 
> full_name='Tecmint HowTos'

# body parameters in raw JSON
> number:=45239
> is_ok:=true
> names:=["tecmint","howtos"]
> user:='{"username": "tecmint", "password": "followus"}'

# write everything in a single line
> Content-Type:application/json page==5 username=tecmint 

您还可以添加HTTPie选项,如图所示。

> --form --auth user:pass
> --verify=no
OR
> --form --auth user:pass  username=tecmint  Content-Type:application/json	

要重置会话(清除所有参数和选项)或退出会话,请运行:

> rm *		#reset session
> exit		#exit session 

 

更多相关资料: http://http-prompt.com/.

 

  • 安卓客户端下载
  • 微信扫一扫
  • weinxin
  • 微信公众号
  • 微信公众号扫一扫
  • weinxin
avatar