Adding headers to Jetty in Wiremock

╄→гoц情女王★ 提交于 2019-12-08 08:02:00

问题


I'm running into CORS issues using the Wiremock standalone jar. I call my mock service using jQuery ajax. Is it possible to add the required "Access-Control-Allow-Origin" header when starting up the server?


回答1:


I got it to work by adding an options.json file in my mappings folder for the CORS preflight request

{
  "request" : {
    "url" : "/myurl",
    "method" : "OPTIONS"    
  },
  "response" : {
    "status" : 200,
    "headers" : {
      "Access-Control-Allow-Origin" : "http://myorigin",
      "Access-Control-Allow-Headers": "accept, content-type",
      "Access-Control-Allow-Methods": "GET, POST"
    }
  }
}

and all my other mappings look like this

{
  "request" : {
    "urlPattern" : "/myurl",
    "method" : "POST",
    "bodyPatterns" : [ {
      "equalToJson" : "{\"foo\":0}",
      "jsonCompareMode" : "LENIENT"
    } ]
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "body-file.json",
    "headers" : {
      "Access-Control-Allow-Origin" : "*"
    }
  }
}

hope it helps



来源:https://stackoverflow.com/questions/27906655/adding-headers-to-jetty-in-wiremock

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!