在http协议中,除了get请求外,另一个最常用的就是post请求了。和get 请求类似,post请求接收一个参数,[ url ]
示例1:调用博客园(http://www.cnblogs.com/)的认证接口(https://passport.cnblogs.com /user/signin),进行用户登录认证。
Create Http Context passport.cnblogs.com scheme=https
Set Request Header Cookie .Cnblogs.AspNetCore.Cookies=CfDJ8Mmb5OBERd5FqtiQlKZZIG41TLord2gXc8xTMoVr_fYAteG89cxtvnObw-OyydeaaiQE8oRPEHPrSvWU32AGKXmVCEtOoQiuKIniNKqCvx2XNfChBRcA47BDeEP4Il6EgeJ6ofQcdG62gN1c-xbk9bgcs7V1yYqUvNYW_tk2dd6Ffei77JuquWXwguCeGtVo4qtGpUXLcP1YEWibXawE4ywbdovJTTihZD7yQB3OljzQjiUv2Q5BvcsqdzyKUxRcgxxSzcHqyDGGslL4Sdvn7ho047ypsdFkgrafsfmzIpQ1;_ga=GA1.2.751066332.1492229820;SERVERID=9b2e527de1fc6430919cfb3051ec3e6c|1492230251|1492230186
Set Request Header Referer https://passport.cnblogs.com/user/signin?ReturnUrl=http://i.cnblogs.com/
Set Request Body {"input1":"V+bOQYKu0ZQXtauwxpGZC4YvvxwLI6/zA9U6Hx2JxXDZIpDXT2Fzravj7AiR5YDsSqEUkYZFnB+komrnfzF5dzBHXN3FOxHdQ5oRoMdDHh/zdxTUuqg/9ev4V4yyT9T8V9fElmxs+BVrF2kNZU35VtkaftQW8qn08Tl0GgdzEZY=","input2":"GAK4VTm2i+a/6bLHRIu8/oEeKJKav3SrU/DS5l3O0BmD/Xk6PEd0vk8GuLs6/obV3dl+y8Hub2Ey9+pO6ip53KIsNKPOeU1y0P0aCIxMGK0jWcs+ydClgeN0KRvxNlO/LTcW1hrXVcRBRAAhRcezdT2OTbYE4frZKIMShHqz+sE=","remember":false}
POST /user/signin
${status} Get Response status
${body} Get Response Body
log ${body}
log ${status}
执行结果:
从执行结果看,我们认证失败了,请求返回的内容为:{"success":false},但是请求返回的http code为200 OK,说明http post 请求已经发送成功了。
【原文归作者所有,欢迎转载,但是保留版权】