Package com.meterware.httpunit
Class WebRequest
java.lang.Object
com.meterware.httpunit.WebRequest
- Direct Known Subclasses:
HeaderOnlyWebRequest
,MessageBodyWebRequest
A request sent to a web server.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WebRequest
(WebForm sourceForm, com.meterware.httpunit.ParameterHolder parameterHolder, SubmitButton button, int x, int y) Constructs a web request from a form.protected
WebRequest
(WebRequest baseRequest, String urlString, String target) Constructs a web request using a base request and a relative URL string.protected
WebRequest
(WebRequestSource requestSource, com.meterware.httpunit.ParameterHolder parameterHolder) protected
WebRequest
(WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target) Constructs a web request using a base URL, a relative URL string, and a target.protected
WebRequest
(String urlString) Constructs a web request using an absolute URL string.protected
WebRequest
(URL urlBase, String urlString) Constructs a web request using a base URL and a relative URL string.protected
WebRequest
(URL urlBase, String urlString, FrameSelector frame, String target) Constructs a web request using a base URL, a relative URL string, and a target.protected
WebRequest
(URL urlBase, String urlString, String target) Constructs a web request using a base URL, a relative URL string, and a target. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
completeRequest
(URLConnection connection) Performs any additional processing necessary to complete the request.protected final String
Returns the character set required for this request.protected String
Returns the content type of this request.Returns a copy of the headers to be sent with this request.getParameter
(String name) Returns the value of a parameter in this web request.protected final com.meterware.httpunit.ParameterHolder
String[]
getParameterValues
(String name) Returns the multiple default values of the named parameter.Returns the query string defined for this request.String[]
Returns an array of all parameter names defined as part of this web request.Returns the target for this web request.getURL()
Returns the final URL associated with this web request.protected final URL
protected String
boolean
isFileParameter
(String name) Returns true if the specified parameter is a file field.protected boolean
Returns true if this request is to be MIME-encoded.protected boolean
maySelectFile
(String parameterName) Returns true if selectFile may be called with this parameter.void
removeParameter
(String name) Removes a parameter from this web request.void
selectFile
(String parameterName, File file) Sets the file for a parameter upload in a web request.void
selectFile
(String parameterName, File file, String contentType) Sets the file for a parameter upload in a web request.void
selectFile
(String parameterName, String fileName, InputStream inputStream, String contentType) Sets the file for a parameter upload in a web request.void
setHeaderField
(String headerName, String headerValue) Sets the value of a header to be sent with this request.void
setImageButtonClickPosition
(int x, int y) Specifies the click position for the submit button.void
setParameter
(String parameterName, com.meterware.httpunit.protocol.UploadFileSpec[] files) Sets the multiple values of a file upload parameter in a web request.void
setParameter
(String name, String value) Sets the value of a parameter in a web request.void
setParameter
(String name, String[] values) Sets the multiple values of a parameter in a web request.toString()
protected void
writeMessageBody
(OutputStream stream) Writes the contents of the message body to the specified stream.
-
Field Details
-
method
the HTTP method defined for this request e.g. DELETE,OPTIONS,HEAD
-
-
Constructor Details
-
WebRequest
Constructs a web request using an absolute URL string. -
WebRequest
Constructs a web request using a base URL and a relative URL string. -
WebRequest
protected WebRequest(WebRequest baseRequest, String urlString, String target) throws MalformedURLException Constructs a web request using a base request and a relative URL string.- Throws:
MalformedURLException
-
WebRequest
Constructs a web request using a base URL, a relative URL string, and a target. -
WebRequest
protected WebRequest(WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target) Constructs a web request using a base URL, a relative URL string, and a target. -
WebRequest
Constructs a web request using a base URL, a relative URL string, and a target. -
WebRequest
protected WebRequest(WebForm sourceForm, com.meterware.httpunit.ParameterHolder parameterHolder, SubmitButton button, int x, int y) Constructs a web request from a form.- Parameters:
sourceForm
- - the WebForm to startFromparameterHolder
- - the parameter holderbutton
- - the submit buttonx
- - x positiony
- - y position
-
WebRequest
protected WebRequest(WebRequestSource requestSource, com.meterware.httpunit.ParameterHolder parameterHolder)
-
-
Method Details
-
setHeaderField
Sets the value of a header to be sent with this request. A header set here will override any matching header set in the WebClient when the request is actually sent.- Parameters:
headerName
- - the name of the headerheaderValue
- - the value to be set
-
getHeaders
Returns a copy of the headers to be sent with this request.- Returns:
- the dictionary of headers
-
getURL
Returns the final URL associated with this web request.- Returns:
- the Uniform Resource Locator for this Web request
- Throws:
MalformedURLException
- if the URL is not o.k.
-
getTarget
Returns the target for this web request. -
getMethod
- Returns:
- the method
-
getQueryString
Returns the query string defined for this request. The query string is sent to the HTTP server as part of the request header. This default implementation returns an empty string. -
setParameter
Sets the value of a parameter in a web request. -
setParameter
Sets the multiple values of a parameter in a web request. -
setParameter
public void setParameter(String parameterName, com.meterware.httpunit.protocol.UploadFileSpec[] files) Sets the multiple values of a file upload parameter in a web request. -
setImageButtonClickPosition
Specifies the click position for the submit button. When a user clioks on an image button, not only the name and value of the button, but also the position of the mouse at the time of the click is submitted with the form. This method allows the caller to override the position selected when this request was created.- Throws:
IllegalRequestParameterException
- thrown if the request was not created from a form with an image button.
-
isFileParameter
Returns true if the specified parameter is a file field. -
selectFile
Sets the file for a parameter upload in a web request. -
selectFile
Sets the file for a parameter upload in a web request. -
selectFile
public void selectFile(String parameterName, String fileName, InputStream inputStream, String contentType) Sets the file for a parameter upload in a web request. -
getRequestParameterNames
Returns an array of all parameter names defined as part of this web request.- Since:
- 1.3.1
-
getParameter
Returns the value of a parameter in this web request.- Returns:
- the value of the named parameter, or empty string if it is not set.
-
getParameterValues
Returns the multiple default values of the named parameter. -
removeParameter
Removes a parameter from this web request. -
toString
-
maySelectFile
Returns true if selectFile may be called with this parameter. -
isMimeEncoded
protected boolean isMimeEncoded()Returns true if this request is to be MIME-encoded. -
getContentType
Returns the content type of this request. If null, no content is specified. -
getCharacterSet
Returns the character set required for this request. -
completeRequest
Performs any additional processing necessary to complete the request.- Throws:
IOException
-
writeMessageBody
Writes the contents of the message body to the specified stream.- Throws:
IOException
-
getURLBase
-
getURLString
-
getParameterHolder
protected final com.meterware.httpunit.ParameterHolder getParameterHolder()
-