天天看點

兩款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/