public static class Net.HttpRequest extends Object implements Pool.Poolable
HttpMethods
for static
referencesMapparameters = new HashMap (); parameters.put("user", "myuser"); HttpRequest httpGet = new HttpRequest(HttpMethods.Get); httpGet.setUrl("http://somewhere.net"); httpGet.setContent(HttpParametersUtils.convertHttpParameters(parameters)); ... Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() { public void handleHttpResponse(HttpResponse httpResponse) { status = httpResponse.getResultAsString(); //do stuff here based on response } public void failed(Throwable t) { status = "failed"; //do stuff here based on the failed attempt } });
Constructor and Description |
---|
Net.HttpRequest() |
Net.HttpRequest(String httpMethod)
Creates a new HTTP request with the specified HTTP method, see
Net.HttpMethods . |
Modifier and Type | Method and Description |
---|---|
String |
getContent()
Returns the content string to be used for the HTTP request.
|
long |
getContentLength()
Returns the content length in case content is a stream.
|
InputStream |
getContentStream()
Returns the content stream.
|
boolean |
getFollowRedirects()
Returns whether 301 and 302 redirects are followed.
|
Map<String,String> |
getHeaders()
Returns a Map
|
String |
getMethod()
Returns the HTTP method of the HttpRequest.
|
int |
getTimeOut()
Returns the timeOut of the HTTP request.
|
String |
getUrl()
Returns the URL of the HTTP request.
|
void |
reset()
Resets the object for reuse.
|
void |
setContent(InputStream contentStream,
long contentLength)
Sets the content as a stream to be used for a POST for example, to transmit custom data.
|
void |
setContent(String content)
Sets the content to be used in the HTTP request.
|
void |
setFollowRedirects(boolean followRedirects)
Sets whether 301 and 302 redirects are followed.
|
void |
setHeader(String name,
String value)
Sets a header to this HTTP request, see
HttpRequestHeader . |
void |
setMethod(String httpMethod)
Sets the HTTP method of the HttpRequest.
|
void |
setTimeOut(int timeOut)
Sets the time to wait for the HTTP request to be processed, use 0 block until it is done.
|
void |
setUrl(String url)
Sets the URL of the HTTP request.
|
public Net.HttpRequest()
public Net.HttpRequest(String httpMethod)
Net.HttpMethods
.httpMethod
- This is the HTTP method for the request, see Net.HttpMethods
public void setUrl(String url)
url
- The URL to set.public void setHeader(String name, String value)
HttpRequestHeader
.name
- the name of the header.value
- the value of the header.public void setContent(String content)
content
- A string encoded in the corresponding Content-Encoding set in the headers, with the data to send with the
HTTP request. For example, in case of HTTP GET, the content is used as the query string of the GET while on a
HTTP POST it is used to send the POST data.public void setContent(InputStream contentStream, long contentLength)
contentStream
- The stream with the content data.public void setTimeOut(int timeOut)
timeOut
- the number of milliseconds to wait before giving up, 0 or negative to block until the operation is donepublic void setFollowRedirects(boolean followRedirects) throws IllegalArgumentException
followRedirects
- whether to follow redirects.IllegalArgumentException
- if redirection is disabled on the GWT backend.public void setMethod(String httpMethod)
public int getTimeOut()
public String getMethod()
public String getUrl()
public String getContent()
public InputStream getContentStream()
public long getContentLength()
public Map<String,String> getHeaders()
public boolean getFollowRedirects()
public void reset()
Pool.Poolable
reset
in interface Pool.Poolable
Copyright © 2014. All rights reserved.