Package com.badlogic.gdx.net
Class HttpRequestBuilder
- java.lang.Object
-
- com.badlogic.gdx.net.HttpRequestBuilder
-
public class HttpRequestBuilder extends java.lang.ObjectA builder forNet.HttpRequests. Make sure to callnewRequest()first, then set the request up and obtain it viabuild()when you are done. It also offers a few utility methods to deal with content encoding and HTTP headers.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringbaseUrlWill be added as a prefix to each URL whenurl(String)is called.static intdefaultTimeoutWill be set for each new HttpRequest.static JsonjsonWill be used for the object serialization in casejsonContent(Object)is called.
-
Constructor Summary
Constructors Constructor Description HttpRequestBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestBuilderbasicAuthentication(java.lang.String username, java.lang.String password)Sets theAuthorizationheader via the Base64 encoded username and password.Net.HttpRequestbuild()Returns theNet.HttpRequestthat has been setup by this builder so far.HttpRequestBuildercontent(java.io.InputStream contentStream, long contentLength)HttpRequestBuildercontent(java.lang.String content)HttpRequestBuilderfollowRedirects(boolean followRedirects)HttpRequestBuilderformEncodedContent(java.util.Map<java.lang.String,java.lang.String> content)Sets the correctContentTypeand encodes the given parameter map, then sets it as the content.HttpRequestBuilderheader(java.lang.String name, java.lang.String value)HttpRequestBuilderincludeCredentials(boolean includeCredentials)HttpRequestBuilderjsonContent(java.lang.Object content)Sets the correctContentTypeand encodes the given content object viajson, then sets it as the content.HttpRequestBuildermethod(java.lang.String httpMethod)HttpRequestBuildernewRequest()Initializes the builder and sets it up to build a newNet.HttpRequest.HttpRequestBuildertimeout(int timeOut)If this method is not called, thedefaultTimeoutwill be used.HttpRequestBuilderurl(java.lang.String url)ThebaseUrlwill automatically be added as a prefix to the given URL.
-
-
-
Field Detail
-
baseUrl
public static java.lang.String baseUrl
Will be added as a prefix to each URL whenurl(String)is called. Empty by default.
-
defaultTimeout
public static int defaultTimeout
Will be set for each new HttpRequest. By default set to1000. Can be overwritten viatimeout(int).
-
json
public static Json json
Will be used for the object serialization in casejsonContent(Object)is called.
-
-
Method Detail
-
newRequest
public HttpRequestBuilder newRequest()
Initializes the builder and sets it up to build a newNet.HttpRequest.
-
method
public HttpRequestBuilder method(java.lang.String httpMethod)
- See Also:
Net.HttpRequest.setMethod(String)
-
url
public HttpRequestBuilder url(java.lang.String url)
ThebaseUrlwill automatically be added as a prefix to the given URL.- See Also:
Net.HttpRequest.setUrl(String)
-
timeout
public HttpRequestBuilder timeout(int timeOut)
If this method is not called, thedefaultTimeoutwill be used.- See Also:
Net.HttpRequest.setTimeOut(int)
-
followRedirects
public HttpRequestBuilder followRedirects(boolean followRedirects)
-
includeCredentials
public HttpRequestBuilder includeCredentials(boolean includeCredentials)
-
header
public HttpRequestBuilder header(java.lang.String name, java.lang.String value)
-
content
public HttpRequestBuilder content(java.lang.String content)
- See Also:
Net.HttpRequest.setContent(String)
-
content
public HttpRequestBuilder content(java.io.InputStream contentStream, long contentLength)
-
formEncodedContent
public HttpRequestBuilder formEncodedContent(java.util.Map<java.lang.String,java.lang.String> content)
Sets the correctContentTypeand encodes the given parameter map, then sets it as the content.
-
jsonContent
public HttpRequestBuilder jsonContent(java.lang.Object content)
Sets the correctContentTypeand encodes the given content object viajson, then sets it as the content.
-
basicAuthentication
public HttpRequestBuilder basicAuthentication(java.lang.String username, java.lang.String password)
Sets theAuthorizationheader via the Base64 encoded username and password.
-
build
public Net.HttpRequest build()
Returns theNet.HttpRequestthat has been setup by this builder so far. After using the request, it should be returned to the pool viaPools.free(request).
-
-