A simple work around should be to remove one of the two "myName" parameters and then set the right value to the remaining "myName" parameter. But I can't use removeParameter() because the parameters are hidden.
So, is there a solution to bypass this problem with the current implementation ?
Is this legal to have several parameters with the same name ?
Note: the only workaround that I've found is to discard duplicated parameters in the getFormControls() of the WebForm class.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It turns out that it is perfectly valid to have multiple parameters with the same name. In your case, the query string submitted by the browser (and HttpUnit) will be:
myName=val1&myName=val2
This confused me a lot when I started, but it appears to be a very common construct. You can get both values by calling getParameterValues( "myName" ), which returns an array. What problem is this giving you?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-09
> It turns out that it is perfectly valid to have multiple parameters with the same name
ok, I didn't know
> In your case, the query string submitted by the browser (and HttpUnit) will be:
>
> myName=val1&myName=val2
yes, and that's the problem because due to an ill-formed HTML page, JTidy has simply merge two forms. In my case "myName=val1&myName=val2" is not a valid request. I want to send only "myName=val1".
btw in the WebForm class, _formParameters is a map. Is there a potential bug ?
thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> yes, and that's the problem because due to an
> ill-formed HTML page, JTidy has simply merge two
> forms. In my case "myName=val1&myName=val2" is
> not a valid request. I want to send only
> "myName=val1".
Oh, that's a different problem. The best thing of course is to persuade the HTML coders to clean up their act. I assume that this is all associated with some complex table structure? Maybe you can get them to use CSS instead, which is much cleaner.
In the long term, a new parser should fix this.
Alternately, you can disable parameter validation, which will let you do whatever you want to your request parameters. Of course, you do lose support for JavaScript onClick and onChange events in that case.
> btw in the WebForm class, _formParameters is a
> map. Is there a potential bug ?
Not that I am aware of. What doesn't work?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-09
> The best thing of course is to persuade the HTML coders to clean up their act.
well in fact I don't use httpunit for testing purpose... It's more to automatically browse the web.
> I assume that this is all associated with some complex table structure?
> Alternately, you can disable parameter validation
With the HttpUnitOptions.setParameterValuesValidated() ? I tryed this solution, but it didn't work.
It seems that the removeParameter() call is just ignored.
I've tryed both :
getResponse( form.getRequest() );
and form.submit();
>> btw in the WebForm class, _formParameters is a
>> map. Is there a potential bug ?
> Not that I am aware of. What doesn't work?
nothing, It's just that I've suspected that multiple values were not managed because a map was used ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you want to post a detailed working (or non-working, as the case may be) example that doesn't work, I may be able to help you. The information provided is not enough.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For some reasons, when parsing an ill-formed HTML page, JTidy can create a form that has several parameters with the same name.
ex :
<form>
<input name="myName" value="val1" type="hidden">
<input name="myName" value="val2" type="hidden">
</form>
A simple work around should be to remove one of the two "myName" parameters and then set the right value to the remaining "myName" parameter. But I can't use removeParameter() because the parameters are hidden.
So, is there a solution to bypass this problem with the current implementation ?
Is this legal to have several parameters with the same name ?
Note: the only workaround that I've found is to discard duplicated parameters in the getFormControls() of the WebForm class.
It's not a bug, it's a feature :)
It turns out that it is perfectly valid to have multiple parameters with the same name. In your case, the query string submitted by the browser (and HttpUnit) will be:
myName=val1&myName=val2
This confused me a lot when I started, but it appears to be a very common construct. You can get both values by calling getParameterValues( "myName" ), which returns an array. What problem is this giving you?
> It turns out that it is perfectly valid to have multiple parameters with the same name
ok, I didn't know
> In your case, the query string submitted by the browser (and HttpUnit) will be:
>
> myName=val1&myName=val2
yes, and that's the problem because due to an ill-formed HTML page, JTidy has simply merge two forms. In my case "myName=val1&myName=val2" is not a valid request. I want to send only "myName=val1".
btw in the WebForm class, _formParameters is a map. Is there a potential bug ?
thanks in advance
> yes, and that's the problem because due to an
> ill-formed HTML page, JTidy has simply merge two
> forms. In my case "myName=val1&myName=val2" is
> not a valid request. I want to send only
> "myName=val1".
Oh, that's a different problem. The best thing of course is to persuade the HTML coders to clean up their act. I assume that this is all associated with some complex table structure? Maybe you can get them to use CSS instead, which is much cleaner.
In the long term, a new parser should fix this.
Alternately, you can disable parameter validation, which will let you do whatever you want to your request parameters. Of course, you do lose support for JavaScript onClick and onChange events in that case.
> btw in the WebForm class, _formParameters is a
> map. Is there a potential bug ?
Not that I am aware of. What doesn't work?
> The best thing of course is to persuade the HTML coders to clean up their act.
well in fact I don't use httpunit for testing purpose... It's more to automatically browse the web.
> I assume that this is all associated with some complex table structure?
I presume, it's :
<form>
...
<table>
...
</form>
...
<form>
</form>
...
</table>
> Alternately, you can disable parameter validation
With the HttpUnitOptions.setParameterValuesValidated() ? I tryed this solution, but it didn't work.
It seems that the removeParameter() call is just ignored.
I've tryed both :
getResponse( form.getRequest() );
and form.submit();
>> btw in the WebForm class, _formParameters is a
>> map. Is there a potential bug ?
> Not that I am aware of. What doesn't work?
nothing, It's just that I've suspected that multiple values were not managed because a map was used ;-)
If you want to post a detailed working (or non-working, as the case may be) example that doesn't work, I may be able to help you. The information provided is not enough.
Here is an example :
put this in a local file named form.html:
<html>
<body>
<form method="post" action="http://www.server_that_doesnt_exist.com/action.asp" name="myForm">
<input type="hidden" name="name1" value="val1">
<input type="hidden" name="name2" value="val2">
<input type="hidden" name="name1" value="val3">
</form>
</body>
</html>
Then the source :
HttpUnitOptions.setScriptingEnabled( false );
HttpUnitOptions.setParameterValuesValidated( false );
WebConversation wc = new WebConversation();
wc.setHeaderField("Connection", "close" );
WebResponse resp = wc.getResponse( "file:D:\\java\\form.html" ); // replace the path of the file.
WebForm form = resp.getFormWithName( "myForm" );
form.removeParameter( "name1" );
form.submit();
So what I want is to send the following query :
http://www.server_that_doesnt_exist.com/action.asp?name2=val2
But Ethereal gives me :
http://www.server_that_doesnt_exist.com/action.asp?name2=val2&name1=val1&name1=val3
Is this the intended behaviour ?
That is absolutely the expected behavior, given the form definition you show. If you need to change the output, try:
HttpUnitOptions.setParameterValuesValidated( false );
WebRequest req = form.getRequest(); // call AFTER disabling validation
req.setParameter( "name1", "val1" ); // remove second value
conversation.getResponse( req );
etc.
> That is absolutely the expected behavior
removeParameter() is not expected to remove a parameter ?
> If you need to change the output, try...
Thanks, that's the solution.