mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
ProxyAndRecord does not save query-parameters, headers and body #46
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raghavendrabankapur on GitHub (Oct 25, 2017).
Originally assigned to: @StefH on GitHub.
When we try to record a request with HttpMethod as post, then we are getting error as below. Can someone please help me if I am missing anything.
I am starting server as below
Error is as below. But when I create a static mapping for the above serevr with Post as method then it works fine. Seeing the below issue only when we try to record it.
@StefH commented on GitHub (Oct 25, 2017):
Which version do you use?
And can you post the client c# code or json?
@raghavendrabankapur commented on GitHub (Oct 25, 2017):
I am using the latest version. I just created a console app and trying to record the requests. I am able to record the requests for get calls. But not able to do it for post/put/delete calls.
C# code is just a console application with above code in the main method.
@StefH commented on GitHub (Oct 25, 2017):
Ok. The latest code from yesterday should fix some issues with headers. However I am not sure I ever tested something else then GET... Will have to check.
@raghavendrabankapur commented on GitHub (Oct 25, 2017):
I update the binaries. Looks like the issue for me is fixed. Thank you for the prompt response.
@StefH commented on GitHub (Oct 25, 2017):
Please double check and close this issue if possible.
@raghavendrabankapur commented on GitHub (Oct 25, 2017):
This has regressed with some other issues. Now the mappings which are made from code are not getting recognized at all.
Example
With the above code, if I run http://localhost:1111/with/get is returning HttpStatusCode 410 with the response of proxy url. This was working fine. This works fine when we put the same settings in the mapping json file. Also when the recording of the above happens and we update the response body, a new mapping file will gets created with the older result rather than picking it from the updated once. Even this was working well before this latest code changes. @StefH .
@StefH commented on GitHub (Oct 25, 2017):
I used latest code, and used you code example above.
The json file generated looks like:
And this file can be use fine as a static mapping.
So can you please help me by providing the steps you take?
@raghavendrabankapur commented on GitHub (Oct 26, 2017):
So now you have the above json, just update the response status code and response body to something else. Then make the same call again, ideally, you should get this request matching and the updated response should be returned. Did you give a try for the coded part of mapping??. If you run the same request again, it is creating a new mapping. It should not be creating a new mapping right if the request matches the mappings which is saved in the json @StefH
@StefH commented on GitHub (Oct 26, 2017):
Ah. Maybe I understand you problem:
When WireMock is in Proxy-mode (ProxyAndRecordSettings defined), it can only be used for that purpose.
The idea is that when you are done proying & recording, you must start and use WireMock in a normal way.
@raghavendrabankapur commented on GitHub (Oct 27, 2017):
Got it. But in the post call, when we pass some post data either as plain text/form data, this is not getting recorded. Is there anything I am missing?
You can try this with the above code by calling it as an API with some post body in postman.
@StefH commented on GitHub (Oct 27, 2017):
When WireMock is in proxy-mode, only the response from the real service (which is proxied) is recorded in a .json file.
What you want is that in case of a body (POST,PUT,PATCH), the Request matcher is defined so that when you send exactly the same request, WireMock will only then return the recorded response.
This is not yet build. I will take a look.
@StefH commented on GitHub (Oct 28, 2017):
@Dreamescaper maybe you also have a clever idea here?
@raghavendrabankapur commented on GitHub (Nov 6, 2017):
@StefH did you get to see why the post body is not getting recorded in the request?
@StefH commented on GitHub (Nov 6, 2017):
I have an idea why this fails. However I dont have the solution at this moment.
I will take a look when I have some time.
@raghavendrabankapur commented on GitHub (Nov 7, 2017):
@StefH even the query string parameters are not getting recorded. Not sure this has been noticed.
@StefH commented on GitHub (Nov 7, 2017):
Code is fixed. You can take a look here :
e25c873765If this is correct, I can create a new NuGet.
@raghavendrabankapur commented on GitHub (Nov 8, 2017):
I will build the solution in my local and let you know if this working fine.
@raghavendrabankapur commented on GitHub (Nov 9, 2017):
I was able to build the solution and see that body and params are getting saved in the mapping file. But this fix has created few other issues. Every time it checks for an exact match in the headers list. Using C# code we cannot do a check if request header list contains required headers, then match the pattern. The same is applicable for the static mappings too.
In the above code, when we invoke the API with post method in postman, it always checks for all the possible headers and also in exact match pattern. Postman generated a token by itself this will keep recording a new mapping. If we remove few headers from the list, it makes an exact match to the list also. Cannot we skip this to make headers contains? @StefH
@StefH commented on GitHub (Nov 11, 2017):
1]
It is indeed not possible to use it in c# code with any ***Matcher. I will take a look to add this or change the code to just generate a string pattern based matcher.
2]
I think that proxy functionality is just for getting a basic mapping. When you have the this basis autogenerated mapping, you have to tweak it and change it according to your needs.
@StefH commented on GitHub (Nov 11, 2017):
1] Code has been changed into
WildcardMatcher. Please take a look.@raghavendrabankapur commented on GitHub (Nov 13, 2017):
@StefH as the header/params/cookie are array of entries, do you think it will make easy if we just have exact match or pattern match for these attributes? Should we not have contains in the array kind of search, where the pattern can be considered as a match when we have that one entry of the header/params/cookies among the list. I guess this will make this tool more flexible.
@StefH commented on GitHub (Nov 14, 2017):
The generated mapping is like:
So by default
WildcardMatcheris used.If you don't want to match on User-Agent, just delete that block.
If you want a different mapping for StefTest, change it to:
@StefH commented on GitHub (Nov 18, 2017):
Clear for you @raghavendrabankapur ?
@raghavendrabankapur commented on GitHub (Nov 18, 2017):
Looks good I guess. Let me check if it's working as the way I was expecting.
@StefH commented on GitHub (Jan 20, 2018):
@raghavendrabankapur : closing this one. If you still have issues, just open a new issue.