com.badlogic.gdx
Class Net.HttpRequest

java.lang.Object
  extended by com.badlogic.gdx.Net.HttpRequest
Enclosing interface:
Net

public static class Net.HttpRequest
extends Object

Contains getters and setters for the following parameters:

Abstracts the concept of a HTTP Request:
 Map parameters = 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 Summary
Net.HttpRequest(String httpMethod)
          Creates a new HTTP request with the specified HTTP method, see Net.HttpMethods.
 
Method Summary
 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.
 Map<String,String> getHeaders()
          Returns a Map with the headers of the HTTP request.
 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 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 setHeader(String name, String value)
          Sets a header to this HTTP request.
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Net.HttpRequest

public Net.HttpRequest(String httpMethod)
Creates a new HTTP request with the specified HTTP method, see Net.HttpMethods.

Parameters:
httpMethod - This is the HTTP method for the request, see Net.HttpMethods
Method Detail

setUrl

public void setUrl(String url)
Sets the URL of the HTTP request.

Parameters:
url - The URL to set.

setHeader

public void setHeader(String name,
                      String value)
Sets a header to this HTTP request. Headers definition could be found at HTTP/1.1: Header Field Definitions document.

Parameters:
name - the name of the header.
value - the value of the header.

setContent

public void setContent(String content)
Sets the content to be used in the HTTP request.

Parameters:
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.

setContent

public void setContent(InputStream contentStream,
                       long contentLength)
Sets the content as a stream to be used for a POST for example, to transmit custom data.

Parameters:
contentStream - The stream with the content data.

setTimeOut

public void setTimeOut(int timeOut)
Sets the time to wait for the HTTP request to be processed, use 0 block until it is done. The timeout is used for both the timeout when establishing TCP connection, and the timeout until the first byte of data is received.

Parameters:
timeOut - the number of milliseconds to wait before giving up, 0 or negative to block until the operation is done

getTimeOut

public int getTimeOut()
Returns the timeOut of the HTTP request.

Returns:
the timeOut.

getMethod

public String getMethod()
Returns the HTTP method of the HttpRequest.


getUrl

public String getUrl()
Returns the URL of the HTTP request.


getContent

public String getContent()
Returns the content string to be used for the HTTP request.


getContentStream

public InputStream getContentStream()
Returns the content stream.


getContentLength

public long getContentLength()
Returns the content length in case content is a stream.


getHeaders

public Map<String,String> getHeaders()
Returns a Map with the headers of the HTTP request.



Copyright © 2013. All Rights Reserved.