-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebClient/MockMVC issue with jquery ajax post #25768
Comments
Thanks for getting in touch, but it feels like this is a question that would be better suited to StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug. The sample you've provided doesn't use Spring Boot - I'd suggest to use Spring Boot instead to dramatically reduce the amount of boilerplate. Also there seems to be a confusion around your usage of jQuery. Right now it's sending the form as a POST, but with an urlencoded request body. You should either switch to GET or send the body as Even better, you could look into the getting started guides for Spring Boot. See https://spring.io/guides/gs/handling-form-submission/ Thanks! |
Hi bclozel, i thinked it was a bug because my code works fine in a tomcat server. This code was an example to reproduce the probem i have with my real application. it works great on chrome. That the reason why i think there is a difference between a real browser and the MockMvc b regards |
Hello, after some investigations, we think there is a problem in HtmlUnitRequestBuilder.content() as you can see in this analyse mor info on this github to reproduce : https://github.com/twendelmuth/spring-test-htmlunit can you reopen the ticket in order to correct spring test ? regards Guillaume |
If I understand correctly, the issue is that we have a POST with "application/x-www-form-urlencoded" data, but the form data is not parsed and used to populate request parameters as Servlet containers do. Wouldn't it make more sense for HtmlUnit to do that so that anything using it (besides Spring's HtmlUnit integration) can also benefit from this improvement? |
Or I guess in HtmlUnit Note that we already have similar logic when using MockMvc (without HtmlUnit). |
@guisimon28 I'm wondering how does it work with HTML form post? I would expect that to run into the same issue. Is the server side controller in that case different? |
thanks for analyse my issue rstoyanchev, i can't debug today. regards |
Still dont have time to debug do you think you can improve htmlunitrequestbuilder like mokckmvc ? |
Hi @rstoyanchev , I work with @guisimon28. When we debug the passage in
|
Thanks @fredarene for the extra findings. It sounds like HtmlUnit is populating Any chance you can update the sample project with both scenarios? |
Hi, quoting my answer here from the HTMLUnit side. I've transformed the Spring Boot project to illustrate the issues as well
|
@twendelmuth I wasn't looking for the example with "AJAX POST" but rather for the example with "html FORM POST" in order to understand why they work differently even though they are the same type of request. In any case I investigated and updated the HtmlUnit issue. I'll wait for the response there. |
in your post on 24/09/2020, you say "Note that we already have similar logic when using MockMvc (without HtmlUnit)." can you apply the same logic with HtmlUnit ? regards |
MockMvc simulates a client and builds the request from the ground up. By contrast HtmlUnit is a client and it is a legitimate question what HtmlUnit should do in this case. From the comment in HtmlUnit/htmlunit#223 (comment) it's clear the main question there is what does a real browser do? Therefore the best way to move this forward is to provide the answers to the questions there first so we can figure out where the fix belongs. I have not gotten to it yet. |
@guisimon28 please take a look at HtmlUnit/htmlunit#223 (comment) |
This issue is superseded, since this seems to be an inconsistency in HtmlUnit's behavior (see issue linked in previous comment). I'm closing this issue for now, we can reopen it if work is required in the Spring Framework codebase. |
…ameters implement WebRequest.getRequestParameters from scratch to take care of the different ways parameters are packed into requests This break the backward compatibility in some way but solves #223 and spring-projects/spring-framework#25768 (hopefully)
Hello,
i am using htmlunit with spring test in order to test all ihm interface from my web application. It works fine with html form (post and get) and with ajax get but i have a problem with ajax post request.
The controller don't received the request. If i replace post by get the junit test case works fine.
this the html view
and the controller
you can also find the complete code on my github https://github.com/guisimon28/spring-test-htmlunit
Can you help me to find if there is some missing configuration or if its a htmlunig bug or pull request ?
Thanks for All
Guillaume
The text was updated successfully, but these errors were encountered: