1

我很难将方法 PATCH 添加到MockServer

我使用下面的 curl 请求并正确创建了期望。

在测试时,我收到以下错误。

预检响应中的 Access-Control-Allow-Methods 不允许方法 PATCH。

我正在使用 docker 容器,并使用以下命令启动容器。

docker run -p 1080:1080 jamesdbloom/mockserver /opt/mockserver/run_mockserver.sh -logLevel INFO -serverPort 1080 -genericJVMOptions '-Dmockserver.enableCORSForAllResponses=false'

我也试过

docker run -p 1080:1080 jamesdbloom/mockserver /opt/mockserver/run_mockserver.sh -logLevel INFO -serverPort 1080 -genericJVMOptions '-Dmockserver.enableCORSForAllResponses=true

curl -v -X PUT "http://localhost:1080/expectation" -d '{
    "httpRequest": {
      "method": "PATCH",
      "path": "/settings",
      "headers": {
          "Host": [".*"],
          "Connection": ["keep-alive"],
          "Origin": [".*"],
          "User-Agent": [".*"],
          "Access-Control-Request-Method": ["PATCH"],
          "access-control-request-headers": ["access-control-allow-origin,content-type"],
          "Accept.*": [".*"],
          "content-length": [".*"]
      },
      "body": {
          "type": "PARAMETERS",
          "parameters":                 
            {
              "email": ["user@example.com"],
              "name": ["User Name"],
              "password": ["supersecret"],
              "password_confirmation": ["supersecret"],
              "username": ["emanresu"]
          }
      }
    },
    "httpResponse": {
        "statusCode": 200,
        "headers": {
          "Content-Type": ["application/json"],
          "Server": ["nginx/1.13.12"],
          "Access-Control-Allow-Origin": ["*"],
          "Access-Control-Allow-Methods" : ["GET, HEAD, OPTIONS, POST, PUT, PATCH"],
          "Access-Control-Allow-Headers" : ["Access-Control-Allow-Origin, Authorization, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Allow-Methods, Access-Control-Request-Method, Access-Control-Request-Headers"],
          "Access-Control-Expose-Headers": ["Access-Control-Allow-Origin, Authorization, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Allow-Methods, Access-Control-Request-Method, Access-Control-Request-Headers"],
          "Access-Control-Max-Age": ["300"],
          "connection": ["close"]
        },
        "body": "{\"status\":\"success\"}"
    }
}'
4

0 回答 0