天天看点

两款REST测试工具

  postman

  简单易用

  rest console

  功能强大

  使用的话用postman就够用了,但是我更喜欢 rest console ,因为她的功能非常强大和全面,一下子就能让你搞清楚你在做的事情,你用不到的功能也可以帮助你更加了解 rest, http请求的过程。

  下面是两个的截图界面

两款REST测试工具

  1. authorization

  basic auth

  digest auth

  oauth 1.0

  2. request method

  get, put, post, patch, delete, link, unlink, copy, head, options, purge

  3. request headers

content-type:

form-data

x-www-form-urlencoded

raw

content-type:multipart/form-data; boundary=----webkitformboundaryvqud0ghtrqdehbqh

request payload:

------webkitformboundaryvqud0ghtrqdehbqh

content-disposition: form-data; name="image"

dddddd

------webkitformboundaryvqud0ghtrqdehbqh--

content-type:application/x-www-form-urlencoded

form data:

image:bbbbbbb

content-type:text/plain;charset=utf-8

image=aaaaaaaaaaaaaa

两款REST测试工具

  这3种方法其中 form-data 是不支持 put 方法的。而用rest console中的 content-type:multpart/form-data 是支持 put 方法的。不知道是不是bug

  4. response body

  支持3种展示方式, 以及常用的xml和json格式。

  pretty

  raw

  preview

  json/xml

  5. response header

connection →

connection

options that are desired for the connection

keep-alive

content-length →93

content-type →application/json; charset=utf-8

date →fri, 01 aug 2014 05:41:56 gmt

keep-alive →timeout=5, max=100

server →apache/2.2.9 (win32) php/5.4.30 mod_fcgid/2.3.6

x-powered-by →php/5.4.30

 2. rest console 测试工具

  1. options

  软件相关设置,配色,主题,高亮设置等(说明这个东东功能比较全面)

  特别说下一个选项就是 help lines, 开启这个选项,对着 rest console的每一个选项,就很容易搞清楚 http 的 请求和响应中的每一个项目是怎么回事

  原创文章,转载请注明 : http://www.cnblogs.com/ganiks/

  2. target

  设置下面内容:

target

request uri : 这个是请求的 URI

request method : put post ...

request timeout

accept

accept: (注意区分这个type和后面的content-type)

*/*(一般都是这个选项)

application/atom+xml

test/plain

application/javascript

application/json

application/http

application/pdf

application/rar

... ...

acceptable language

  3. body

  content headers

  content-type: mime type of the request body(跟put和post方法配合使用)

  application/x-www-form-urlencoded

  text/plain

  multipart/form-data

  这3种是在 postman中支持的3种,但其实有很多很多种,在 rest console 中的输入框中输入几个字母,会自动匹配库中的很多选项

  acceptable encoding: 比如 utf-8(参考 http compression)

  content-md5: 比如 q2hly2sgsw50zwdyaxr5iq==

  request payload

  raw body: image=ccccccccc

  request params: key=>value

  attachements: upload files

  custom headers

  request parameters

  对照个例子:

accept:*/*

accept-encoding:gzip,deflate,sdch

accept-language:zh-cn,zh;q=0.8,en-us;q=0.6,en;q=0.4

authorization:basic mtawlxrva2vuog==

cache-control:no-cache

connection:keep-alive

content-length:20

host:192.168.4.126

origin:chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm

user-agent:mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, like gecko) chrome/36.0.1985.125 safari/537.36

  4. authorization

  setup oauth

  refresh oauth

  5. headers

  headers

  max-forwards: 10 (限制消息可以穿破 的代理和网关的层数)

  range

  from: (发送消息者的邮件地址)

  warning

  pragma

  ...

  cache (内容太多了)

  common non-standard request headers

  6. response

response body: 支持 json xml html css 等高亮格式

{

"id": "162",

"image": "cccccccc",

"link": "dd2",

"show_date": "0000-00-00",

"state": 1,

"show_order": 0

}

raw body

{"id":"162","image":"cccccccc","link":"dd2","show_date":"0000-00-00","state":1,"show_order":0}

response headers

status code: 200

date: fri, 01 aug 2014 06:39:00 gmt

server: apache/2.2.9 (win32) php/5.4.30 mod_fcgid/2.3.6

connection: keep-alive

x-powered-by: php/5.4.30

content-length: 94

keep-alive: timeout=5, max=100

content-type: application/json; charset=utf-8

response preview

request body

request url: http://192.168.4.126/news/162

request method: put

params: {}

request headers

content-type: multipart/form-data

authorization: basic mtawlxrva2vuog==

accept: */*

origin: chrome-extension: //rest-console-id

user-agent: mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, like gecko) chrome/36.0.1985.125 safari/537.36

  3. http请求的accept参数

  上面提到了一个设置的地方, accept 和 content-type

  这两个参数很重要

  前者一般如果不设置默认的是 */*, postman 和 restconsole 工具中默认的是 application/json,因此在不设置 headers:accept 参数的情况下返回的按照 json格式;

  而普通的浏览器中返回的则默认是 application/xml 格式。

  后者这个 type 指的是head body 内容的 类型

  这就是为什么这两个参数分别被 rest console 工具分别放在了 2. target 3. body 中。

  在 yii 中默认支持的 rest api 格式有 xml 和 json, yii 会根据 请求的 head 的 accept 参数来返回对应格式的数据。

  这个参数 在chrome 中可以修改默认值吗?

最新内容请见作者的github页:http://qaseven.github.io/