text: (window.webpackJsonp=window.webpackJsonp||[]).push([[32],{500:function(t,e,s){"use strict";s.r(e);var n=s(5),a=Object(n.a)({},(function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("blockquote",[s("p",[t._v("官方文档地址 "),s("code",[t._v("https://www.jetbrains.com/help/idea/restful-webservices.html")])])]),t._v(" "),s("h3",{attrs:{id:"准备"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#准备"}},[t._v("#")]),t._v(" 准备")]),t._v(" "),s("h4",{attrs:{id:"目录结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#目录结构"}},[t._v("#")]),t._v(" 目录结构")]),t._v(" "),s("blockquote",[s("p",[s("em",[t._v("不要使用默认的目录")])]),t._v(" "),s("ol",[s("li",[s("p",[t._v("在根目录下新建 "),s("code",[t._v("http-client")])])]),t._v(" "),s("li",[s("p",[t._v("在 "),s("code",[t._v("http-client")]),t._v(" 下新建 "),s("code",[t._v("rest-api.http")])]),t._v(" "),s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v("### 这是多个请求之间的分隔符\nGET http://localhost:89/commonApi/listDataDic?type=bool&data={{data}}\n"),s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Accept:")]),t._v(" */*\n"),s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Cache-Control:")]),t._v(" no-cache\n# 可以与历史结果进行比对\n<> 2020-06-22T102207.200.txt \n<> 2020-06-22T102023.200.txt\n<> 2020-06-22T101401.200.txt\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br"),s("span",{staticClass:"line-number"},[t._v("3")]),s("br"),s("span",{staticClass:"line-number"},[t._v("4")]),s("br"),s("span",{staticClass:"line-number"},[t._v("5")]),s("br"),s("span",{staticClass:"line-number"},[t._v("6")]),s("br"),s("span",{staticClass:"line-number"},[t._v("7")]),s("br"),s("span",{staticClass:"line-number"},[t._v("8")]),s("br")])])]),t._v(" "),s("li",[s("p",[t._v("点击旁边的绿色箭头即可运行")])]),t._v(" "),s("li",[s("p",[t._v("结果日志保存在 "),s("code",[t._v(".idea\\httpRequests")])])])])]),t._v(" "),s("h4",{attrs:{id:"restful-风格说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#restful-风格说明"}},[t._v("#")]),t._v(" RESTFUL 风格说明")]),t._v(" "),s("blockquote",[s("p",[s("code",[t._v("POST")]),t._v(": 新增数据")]),t._v(" "),s("p",[s("code",[t._v("PUT")]),t._v(": 修改数据")]),t._v(" "),s("p",[s("code",[t._v("GET")]),t._v(": 查询数据")]),t._v(" "),s("p",[s("code",[t._v("DELETE")]),t._v(": 删除数据")]),t._v(" "),s("p",[s("em",[t._v("上面是常用的请求, 注意使用该风格, 路径中不要包含 list/get/add/update/delete 等字眼")])]),t._v(" "),s("p",[t._v("如新增用户: POST userInfo")])]),t._v(" "),s("h4",{attrs:{id:"变量"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#变量"}},[t._v("#")]),t._v(" 变量")]),t._v(" "),s("blockquote",[s("ol",[s("li",[s("p",[t._v("内置变量: "),s("code",[t._v("uuid")]),t._v(" "),s("code",[t._v("timestamp")]),t._v(" "),s("code",[t._v("randomInt")])])]),t._v(" "),s("li",[s("p",[t._v("内置变量使用方式:")]),t._v(" "),s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v("PUT userInfo/{{$uuid}}\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br")])])]),t._v(" "),s("li",[s("p",[t._v("自定义变量, 新建文件 "),s("code",[t._v("http-client.env.json")]),t._v(" "),s("em",[t._v("特别注意, 该文件必须在项目中, 可以在根目录, 也可以在我们新建的 "),s("code",[t._v("http-client")]),t._v(" 里面")])]),t._v(" "),s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v('{\n  "dev": {\n    "host": "127.0.0.1:89",\n    "common": "127.0.0.1:89/commonApi"\n  }\n}\n')])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br"),s("span",{staticClass:"line-number"},[t._v("3")]),s("br"),s("span",{staticClass:"line-number"},[t._v("4")]),s("br"),s("span",{staticClass:"line-number"},[t._v("5")]),s("br"),s("span",{staticClass:"line-number"},[t._v("6")]),s("br")])])]),t._v(" "),s("li",[s("p",[t._v("自定义变量使用方式")]),t._v(" "),s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v("GET {{common}}/listDataDic?type=bool\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br")])])]),t._v(" "),s("li",[s("p",[t._v("待补充 "),s("code",[t._v("http-client.private.env.json")])])])])]),t._v(" "),s("h4",{attrs:{id:"脚本"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#脚本"}},[t._v("#")]),t._v(" 脚本")]),t._v(" "),s("blockquote",[s("p",[s("em",[t._v("该工具也支持脚本的方式, 脚本语言是 "),s("a",{attrs:{href:"https://www.ecma-international.org/ecma-262/5.1/",target:"_blank",rel:"noopener noreferrer"}},[t._v("ECMAScript 5.1"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("格式:")]),t._v(" "),s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v("GET {{common}}/listDataDic?type=bool\n > {% ... %}\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br")])])]),t._v(" "),s("h4",{attrs:{id:"文件上传"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#文件上传"}},[t._v("#")]),t._v(" 文件上传")]),t._v(" "),s("blockquote",[s("div",{staticClass:"language-http line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[t._v("### 这样就可以测试文件上传了\nPOST {{host}}/upload/addFile HTTP/1.1\n"),s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type:")]),t._v(" multipart/form-data; boundary=boundary\n--boundary\n"),s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Disposition:")]),t._v(' form-data; name="files"; filename="input.txt"\n< ./input.txt\n')])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br"),s("span",{staticClass:"line-number"},[t._v("3")]),s("br"),s("span",{staticClass:"line-number"},[t._v("4")]),s("br"),s("span",{staticClass:"line-number"},[t._v("5")]),s("br"),s("span",{staticClass:"line-number"},[t._v("6")]),s("br")])])]),t._v(" "),s("blockquote",[s("p",[s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-client-reference.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("client"),s("OutboundLink")],1),t._v(" 可以获取 session metadata")]),t._v(" "),s("table",[s("thead",[s("tr",[s("th",[t._v("Method")]),t._v(" "),s("th",[t._v("Parameters")]),t._v(" "),s("th",[t._v("Description")])])]),t._v(" "),s("tbody",[s("tr",[s("td",[s("code",[t._v("test")])]),t._v(" "),s("td",[s("code",[t._v("testName")]),t._v(" (string)"),s("code",[t._v("func")]),t._v(" (function)")]),t._v(" "),s("td",[t._v("Creates a test with the name "),s("code",[t._v("testName")]),t._v(" and body "),s("code",[t._v("func")]),t._v(". All tests are executed after the response handler script.")])]),t._v(" "),s("tr",[s("td",[s("code",[t._v("assert")])]),t._v(" "),s("td",[s("code",[t._v("condition")]),t._v(" (boolean)"),s("code",[t._v("message")]),t._v(" (string)")]),t._v(" "),s("td",[t._v("Checks that the specified "),s("code",[t._v("condition")]),t._v(" is "),s("code",[t._v("true")]),t._v("; throws an exception otherwise. The optional "),s("code",[t._v("message")]),t._v(" parameter serves as an exception message.")])]),t._v(" "),s("tr",[s("td",[s("code",[t._v("log")])]),t._v(" "),s("td",[s("code",[t._v("text")])]),t._v(" "),s("td",[t._v("Prints "),s("code",[t._v("text")]),t._v(" to the response handler or test stdout and then terminates the line.")])])])]),t._v(" "),s("div",{staticClass:"language-js line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-js"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// global methods")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 可以存储请求的结果数据到一个变量中, 下一个请求可以用这个数据")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"auth_token"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" response"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("json"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("token"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isEmpty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("clear")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("global"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("clearAll")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// methods")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nclient"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("assert")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nclinet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br"),s("span",{staticClass:"line-number"},[t._v("3")]),s("br"),s("span",{staticClass:"line-number"},[t._v("4")]),s("br"),s("span",{staticClass:"line-number"},[t._v("5")]),s("br"),s("span",{staticClass:"line-number"},[t._v("6")]),s("br"),s("span",{staticClass:"line-number"},[t._v("7")]),s("br"),s("span",{staticClass:"line-number"},[t._v("8")]),s("br"),s("span",{staticClass:"line-number"},[t._v("9")]),s("br"),s("span",{staticClass:"line-number"},[t._v("10")]),s("br"),s("span",{staticClass:"line-number"},[t._v("11")]),s("br"),s("span",{staticClass:"line-number"},[t._v("12")]),s("br"),s("span",{staticClass:"line-number"},[t._v("13")]),s("br"),s("span",{staticClass:"line-number"},[t._v("14")]),s("br")])]),s("p",[s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-response-reference.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("response"),s("OutboundLink")],1),t._v(" 可以获取返回值")]),t._v(" "),s("table",[s("thead",[s("tr",[s("th",[t._v("Property")]),t._v(" "),s("th",[t._v("Description")])])]),t._v(" "),s("tbody",[s("tr",[s("td",[s("code",[t._v("body")]),t._v(" (string|object)")]),t._v(" "),s("td",[t._v("Response content, which is a string or a JSON object if the response's "),s("em",[t._v("content-type")]),t._v(" is "),s("em",[t._v("application/json")]),t._v(".")])]),t._v(" "),s("tr",[s("td",[s("code",[t._v("headers")]),t._v(" ("),s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-response-reference.html#headers-reference",target:"_blank",rel:"noopener noreferrer"}},[t._v("ResponseHeaders"),s("OutboundLink")],1),t._v(")")]),t._v(" "),s("td",[t._v("The "),s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-response-reference.html#headers-reference",target:"_blank",rel:"noopener noreferrer"}},[t._v("response headers storage object"),s("OutboundLink")],1),t._v(".")])]),t._v(" "),s("tr",[s("td",[s("code",[t._v("status")]),t._v(" (int)")]),t._v(" "),s("td",[t._v("Response status, for example, "),s("em",[t._v("200")]),t._v(" or "),s("em",[t._v("404")]),t._v(".")])]),t._v(" "),s("tr",[s("td",[s("code",[t._v("contentType")]),t._v(" ("),s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-response-reference.html#content-type-reference",target:"_blank",rel:"noopener noreferrer"}},[t._v("ContentType"),s("OutboundLink")],1),t._v(")")]),t._v(" "),s("td",[t._v("The "),s("a",{attrs:{href:"https://www.jetbrains.com/help/idea/http-response-reference.html#content-type-reference",target:"_blank",rel:"noopener noreferrer"}},[t._v("contentType object"),s("OutboundLink")],1),t._v(", which holds the data on the "),s("em",[t._v("Content-Type")]),t._v(" response header value.")])])])]),t._v(" "),s("div",{staticClass:"language-js line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-js"}},[s("code",[t._v("response"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("json "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 获取 JSON 类型返回值")]),t._v("\n\nresponse"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("status "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 404.etc")]),t._v("\n\nresponse"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("headers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("valueOf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("headerName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// get first value")]),t._v("\nresponse"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("headers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("valuesOf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("headerName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// get all values")]),t._v("\n\nresponse"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ContentType"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("mimeType "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//The MIME type of the response, for example, text/plain, text/xml, application/json.")]),t._v("\n\nresponse"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ContentType"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("charset "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//The string representation of the response charset, for example, utf-8.")]),t._v("\n\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br"),s("span",{staticClass:"line-number"},[t._v("2")]),s("br"),s("span",{staticClass:"line-number"},[t._v("3")]),s("br"),s("span",{staticClass:"line-number"},[t._v("4")]),s("br"),s("span",{staticClass:"line-number"},[t._v("5")]),s("br"),s("span",{staticClass:"line-number"},[t._v("6")]),s("br"),s("span",{staticClass:"line-number"},[t._v("7")]),s("br"),s("span",{staticClass:"line-number"},[t._v("8")]),s("br"),s("span",{staticClass:"line-number"},[t._v("9")]),s("br"),s("span",{staticClass:"line-number"},[t._v("10")]),s("br"),s("span",{staticClass:"line-number"},[t._v("11")]),s("br")])])])])}),[],!1,null,null,null);e.default=a.exports}}]);