Wiremock 2.27.1 - Request was not matched for POST method

4,422 views
Skip to first unread message

Nagajothi Kaliappan

unread,
Aug 17, 2020, 2:57:35 AM8/17/20
to wiremock-user
Hello Team,

As a newbie to wiremock, I started some test to do poc for my mobile app.

The intention of POC is, to automate the app local notification, for that I need to mock the response  made by my app(client).

I read the documentation and set up my stub for POST request with right headers and body, but when my app (client) makes call to that endpoint, only the url is matching with the stub setting and for headers,  it says Header is not present and Header does not match.

I don't understand why the headers are missing and not matching. Your timely help is much appreciated. Thank you in advance.

I have started the wiremock server and setup the stub in @Beforeclass and close the server @Afterclass in my testrunner class.

Starting Server, Stub set up and Closing Server methods:
static WireMockServer wireMockServer;

@BeforeClass
    public static void setup () {
        wireMockServer = new WireMockServer(8090);
        wireMockServer.start();
        setupStub();
    }
@AfterClass
    public static void teardown () {
wireMockServer.stop();
    }

public static void setupStub() {
wireMockServer.stubFor(post(urlEqualTo("/twlYourWarehouseTest/GetProductsRanking.json"))
    .withHeader("sub-key", equalTo("xxxxxxxxxxxxxx"))
    .withHeader("Content-Type", containing("application/json"))
    .withHeader("X-xxx-Environment", equalTo("qat"))
    .withHeader("X-xxx-Device", equalTo("Android"))
    .withHeader("X-xxx-API-Version", equalTo("3.7"))
    .withRequestBody(containing("products"))
                .willReturn(aResponse()
                .withHeader("Content-Type", "application/json; charset=utf-8")
                        .withStatus(200)
                        .withBodyFile("/json/GetProductsRanking.json")));
    }

please let me know for any further information.


MicrosoftTeams-image (13).pngchls.PNG
Eclipse.PNG

thilmano_wiremockuser

unread,
Aug 17, 2020, 3:58:43 AM8/17/20
to wiremock-user
hey.. it looks like a clear mismatch of request headers.. you have your stub looking for Content-Type which contains 'application/json', whereas the actual request you pass has a different request header. which is, content-type= application/x-www-form-urlencoded

please try to tweak your matching conditions on the request-header, it should work fine..


thanks
Senthil Manohar

Nagajothi Kaliappan

unread,
Aug 17, 2020, 5:46:19 AM8/17/20
to wiremock-user
Hello Senthil,

Thanks for your help. I modifed the content-type in stup set as below

.withHeader("Content-Type", containing("application/")) - "Header does not match" disappears but other errors like Header is missing still exists.

Wiremock_Error.PNG




If you see the charles proxy screenshot attached below, I have highlighted the headers used by the endpoint "GetProductsRanking.json". The same headers were used to set up the stub and while the client make the call to this endpoint the request captured in charles shows correct header information. But no clue why it says header/body is not present.

If you need more information, please let me know.

chls.PNG

Regards,
Jothi.

thilmano_wiremockuser

unread,
Aug 17, 2020, 6:21:55 AM8/17/20
to wiremock-user
Hi Jothi.. correct me if I am wrong..

I see only Content-type being sent in the request, but in your stubs, you have defined few other header parameters as well. (like X-TWL-environment, device, api version etc)

and you say, when you publish the request from charles proxy as well as your clients, you send all the header-parameters you have defined in the stubs.. 

were you able to check any logs, to ascertain the exact req-headers?
Reply all
Reply to author
Forward
0 new messages