-1

My application does post request to url:

https://myserver.domain.com/authenticate/credentials

OkHttp client interceptor shows my headers:

11-17 10:10:56.780 3140-3304/com.myapp.debug D/OkHttp: Content-Type: application/x-www-form-urlencoded

11-17 10:10:56.780 3140-3304/com.myapp.debug D/OkHttp: Content-Length: 187

11-17 10:10:56.781 3140-3304/com.myapp.debug D/OkHttp: Authorization: Basic authorisationkeyfortest5430593045903495034905==

11-17 10:10:56.781 3140-3304/com.myapp.debug D/OkHttp: email=testlogin%40gmail.com&password=test%4012&deviceId=1484564155&deviceLabel=Android%20SDK%20built%20for%20x86_64&deviceType=ANDROID&deviceVersion=23%20%28REL%29

I have created standalone WireMock server and I want redirect every POST request from my APP to my WireMock server. Thats why I have added *.JSON with request definition:

{
    "request": {
        "method": "POST",
        "urlPattern": ".*"
    },
    "response": {
        "proxyBaseUrl" : "https://myserver.domain.com/",
        "additionalProxyRequestHeaders": {
            "Authorization": "Basic authorisationkeyfortest5430593045903495034905==  "
        }
    }
}

What I expect that should happen:

When I change basepath of my Http client from https://myserver.domain.com/ to http://myserveraddress.com/ - then every request from my app should go to my MockServer. And MockServer according to JSON above should proxy/forward that request to https://myserver.domain.com/ and return the same response - so everything should work fine.

What happens:

Each POST request returns status 200 but body is empty. (it should return authenticated user object)


Question: Is it possible to achieve that? Am I doing something wrong?

F1sher
  • 7,140
  • 11
  • 48
  • 85

1 Answers1

0

Try to add your body in "__files" folder and set path in "bodyFileName"

{
"request": {
    "method": "POST",
    "urlPattern": ".*"
},
"response": {
    "proxyBaseUrl" : "https://myserver.domain.com/",
    "additionalProxyRequestHeaders": {
        "Authorization": "Basic authorisationkeyfortest5430593045903495034905==  "
    },
    "bodyFileName":".*.json"
}

In JSON file put your answer. For example:

{ "errorCode": 0, "errorMessage": "", "result": { "filed1":"value", "filed2":"value" } }

  • How should this file of body look like? Can it be any file with .json extension - even empty one and response will be overwritten on it? – F1sher Nov 17 '16 at 13:10
  • I've copy pasted exact "bodyFileName" as your and created response.json from code below. I still receive empty body. By the way I am sure I am connecting remote server because if I remove "additionalProxyRequestHeaders" with "Authentication" header I get 401, otherwise I have 200. – F1sher Nov 17 '16 at 15:11
  • AFAIK WireMock is for stubbing/mocking, not a proxy. – Krzysztof Tomaszewski Jun 27 '22 at 06:54