对于ajax.googleapis.com,Wiremock代理失败

时间:2014-02-13 23:08:55

标签: mocking

通过以下方式调用wiremock:

java -jar wiremock-1.42-standalone.jar --proxy-all="http://ajax.googleapis.com" \
--record-mappings --verbose

并通过以下方式发出请求:

curl "http://localhost:8080/ajax/services/search/images?v=1.0&q=sun&rsz=2"

wiremock详细日志显示:

Proxying: GET http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=sun&rsz=2

映射文件显示:

{
  "request" : {
    "url" : "/ajax/services/search/images?v=1.0&q=sun&rsz=2",
    "method" : "GET"
  },
  "response" : {
    "status" : 404,
    "bodyFileName" : "body-search-images-E1cwy.json",
    "headers" : {
      "Content-Type" : "text/html; charset=UTF-8",
      "X-Content-Type-Options" : "nosniff",
      "Date" : "Thu, 13 Feb 2014 22:34:35 GMT",
      "Server" : "sffe",
      "Content-Length" : "1478",
      "X-XSS-Protection" : "1; mode=block",
      "Alternate-Protocol" : "80:quic"
    }
  }
}

当然,未经批准的请求会返回200:

curl "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=sun&rsz=2" {"responseData": {"results": [{"GsearchResultClass":"GimageSearch","width":"4044","height":"3860","imageId":"ANd9GcQFr9rx7PeezmbnESrHJIp8im8m5Vs-JYpUEZ9aosmy4cBoOKQUUru6HwNQ","tbWidth":"150","tbHeight":"143","unescapedUrl":"http://upload.wikimedia.org/wikipedia/commons/b/b4/The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA's_Solar_Dynamics_Observatory_-_20100819.jpg","url":"http://upload.wikimedia.org/wikipedia/commons/b/b4/The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA%27s_Solar_Dynamics_Observatory_-_20100819.jpg","visibleUrl":"en.wikipedia.org","title":"\u003cb\u003eSun\u003c/b\u003e - Wikipedia, the free encyclopedia","titleNoFormatting":"Sun - Wikipedia, the free encyclopedia","originalContextUrl":"http://en.wikipedia.org/wiki/Sun","content":"\u003cb\u003eSun\u003c/b\u003e","contentNoFormatting":"Sun","tbUrl":"http://t3.gstatic.com/images?q\u003dtbn:ANd9GcQFr9rx7PeezmbnESrHJIp8im8m5Vs-JYpUEZ9aosmy4cBoOKQUUru6HwNQ"},{"GsearchResultClass":"GimageSearch","width":"1920","height":"1080","imageId":"ANd9GcStbg7L2A6SajSn3eaGX7pPzV72S3JZRlxJ6B6OClcBN90xkXmyNi4IbNs8","tbWidth":"150","tbHeight":"84","unescapedUrl":"http://upload.wikimedia.org/wikipedia/commons/a/a3/Giant_prominence_on_the_sun_erupted.jpg","url":"http://upload.wikimedia.org/wikipedia/commons/a/a3/Giant_prominence_on_the_sun_erupted.jpg","visibleUrl":"en.wikipedia.org","title":"\u003cb\u003eSun\u003c/b\u003e - Wikipedia, the free encyclopedia","titleNoFormatting":"Sun - Wikipedia, the free encyclopedia","originalContextUrl":"http://en.wikipedia.org/wiki/Sun","content":"they pass the \u003cb\u003eSun\u003c/b\u003e. [170]","contentNoFormatting":"they pass the Sun. [170]","tbUrl":"http://t1.gstatic.com/images?q\u003dtbn:ANd9GcStbg7L2A6SajSn3eaGX7pPzV72S3JZRlxJ6B6OClcBN90xkXmyNi4IbNs8"}],"cursor":{"resultCount":"5,640,000,000","pages":[{"start":"0","label":1},{"start":"2","label":2},{"start":"4","label":3},{"start":"6","label":4},{"start":"8","label":5},{"start":"10","label":6},{"start":"12","label":7},{"start":"14","label":8}],"estimatedResultCount":"5640000000","currentPageIndex":0,"moreResultsUrl":"http://www.google.com/images?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003dsun","searchResultTime":"0.35"}}, "responseDetails": null, "responseStatus": 200}

这是一个错误还是我错过了什么?

1 个答案:

答案 0 :(得分:0)

记录的映射指向文件中的主体内容,而不是直接嵌入它。

引用的正文文件(与映射文件同名但在__files目录下)是否包含您在curl请求中看到的内容?