如何使用mockbin API正确创建bin?

时间:2016-01-12 13:24:44

标签: php api rest http mocking

我正在尝试使用mockbin API创建一个bin。我试过PHP/cUrl,SoapUI和Postman,但我一直得到空的响应体:

请求:

POST /bin/create/view HTTP/1.1
Host: mockbin.org
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache

响应:

HTTP/1.1 200 OK
Date: Tue, 12 Jan 2016 13:21:50 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d183c7edefea549cc0bbe219ac11fe7c81452604909; expires=Wed, 11-Jan-17 13:21:49 GMT; path=/; domain=.mockbin.org; HttpOnly
Vary: X-HTTP-Method-Override, Accept, Accept-Encoding
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: host,connection,accept-encoding,x-forwarded-for,cf-ray,x-forwarded-proto,cf-visitor,content-type,accept,user-agent,via,cf-connecting-ip,x-request-id,x-forwarded-port,connect-time,x-request-start,total-route-time,content-length
Access-Control-Allow-Credentials: true
Content-Encoding: gzip
Via: 1.1 vegur
Server: cloudflare-nginx
CF-RAY: 26392aae22092ac1-WAW

预期回应:

HTTP/1.1 200 OK
Location: http://mockbin.org/3c149e20-bc9c-4c68-8614-048e6023a108
Content-Type: application/json; charset=utf-8
Content-Length: 38

"3c149e20-bc9c-4c68-8614-048e6023a108"

其他API方法正常工作,即echo

1 个答案:

答案 0 :(得分:1)

看起来mockbin API文档中存在错误。我在本地安装它并在使用html表单创建mockbin时检查发送请求。好像是proper request is

POST /bin/create HTTP/1.1
Host: mockbin.com
Accept: application/json
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

response=%7B%22status%22%3A200%2C%22statusText%22%3A%22OK%22%2C%22httpVersion%22%3A%22HTTP%2F1.1%22%2C%22headers%22%3A%5B%5D%2C%22cookies%22%3A%5B%5D%2C%22content%22%3A%7B%22mimeType%22%3A%22text%2Fplain%22%2C%22text%22%3A%22%22%7D%7D