Package com.sk89q.worldedit.util.net
Class HttpRequest
java.lang.Object
com.sk89q.worldedit.util.net.HttpRequest
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Used to buffer the response in memory.static class
Used withbodyUrlEncodedForm(Form)
. -
Method Summary
Modifier and TypeMethodDescriptionSubmit data.Submit form data.Submit form data.void
close()
execute()
Execute the request.expectResponseCode(int... codes)
Require that the response code is one of the given response codes.static HttpRequest
Perform a GET request.Get the input stream.int
Get the response code.Add a header.static HttpRequest
Perform a POST request.static HttpRequest
Perform a request.Buffer the returned response.saveContent(File file)
Save the result to a file.saveContent(OutputStream out)
Save the result to an output stream.static URL
Create a newURL
and throw aRuntimeException
if the URL is not valid.
-
Method Details
-
body
Submit data.- Returns:
- this object
-
bodyUrlEncodedForm
Submit form data.- Parameters:
form
- the form- Returns:
- this object
-
bodyMultipartForm
Submit form data.- Parameters:
form
- the form- Returns:
- this object
-
header
Add a header.- Parameters:
key
- the header keyvalue
- the header value- Returns:
- this object
-
execute
Execute the request. After execution,close()
should be called.- Returns:
- this object
- Throws:
IOException
- on I/O error
-
expectResponseCode
Require that the response code is one of the given response codes.- Parameters:
codes
- a list of codes- Returns:
- this object
- Throws:
IOException
- if there is an I/O error or the response code is not expected
-
getResponseCode
Get the response code.- Returns:
- the response code
- Throws:
IOException
- on I/O error
-
getInputStream
Get the input stream.- Returns:
- the input stream
-
returnContent
Buffer the returned response.- Returns:
- the buffered response
- Throws:
IOException
- on I/O errorInterruptedException
- on interruption
-
saveContent
Save the result to a file.- Parameters:
file
- the file- Returns:
- this object
- Throws:
IOException
- on I/O errorInterruptedException
- on interruption
-
saveContent
Save the result to an output stream.- Parameters:
out
- the output stream- Returns:
- this object
- Throws:
IOException
- on I/O errorInterruptedException
- on interruption
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
get
Perform a GET request.- Parameters:
url
- the URL- Returns:
- a new request object
-
post
Perform a POST request.- Parameters:
url
- the URL- Returns:
- a new request object
-
request
Perform a request.- Parameters:
method
- the methodurl
- the URL- Returns:
- a new request object
-
url
Create a newURL
and throw aRuntimeException
if the URL is not valid.- Parameters:
url
- the url- Returns:
- a URL object
- Throws:
RuntimeException
- if the URL is invalid
-