MCPcopy
hub / github.com/libgdx/libgdx / HttpRequest

Class HttpRequest

gdx/src/com/badlogic/gdx/Net.java:163–307  ·  view source on GitHub ↗

Contains getters and setters for the following parameters: httpMethod: GET or POST are most common, can use Net.HttpMethods HttpMethods for static references url: the url headers: a map of the headers, setter can b

Source from the content-addressed store, hash-verified

161 * </pre>
162 */
163 public static class HttpRequest implements Poolable {
164
165 private String httpMethod;
166 private String url;
167 private Map<String, String> headers;
168 private int timeOut = 0;
169
170 private String content;
171 private InputStream contentStream;
172 private long contentLength;
173
174 private boolean followRedirects = true;
175
176 private boolean includeCredentials = false;
177
178 public HttpRequest () {
179 this.headers = new HashMap<String, String>();
180 }
181
182 /** Creates a new HTTP request with the specified HTTP method, see {@link HttpMethods}.
183 * @param httpMethod This is the HTTP method for the request, see {@link HttpMethods} */
184 public HttpRequest (String httpMethod) {
185 this();
186 this.httpMethod = httpMethod;
187 }
188
189 /** Sets the URL of the HTTP request.
190 * @param url The URL to set. */
191 public void setUrl (String url) {
192 this.url = url;
193 }
194
195 /** Sets a header to this HTTP request, see {@link HttpRequestHeader}.
196 * @param name the name of the header.
197 * @param value the value of the header. */
198 public void setHeader (String name, String value) {
199 headers.put(name, value);
200 }
201
202 /** Sets the content to be used in the HTTP request.
203 * @param content A string encoded in the corresponding Content-Encoding set in the headers, with the data to send with the
204 * HTTP request. For example, in case of HTTP GET, the content is used as the query string of the GET while on a
205 * HTTP POST it is used to send the POST data. */
206 public void setContent (String content) {
207 this.content = content;
208 }
209
210 /** Sets the content as a stream to be used for a POST for example, to transmit custom data.
211 * @param contentStream The stream with the content data. */
212 public void setContent (InputStream contentStream, long contentLength) {
213 this.contentStream = contentStream;
214 this.contentLength = contentLength;
215 }
216
217 /** 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
218 * the timeout when establishing TCP connection, and the timeout until the first byte of data is received.
219 * @param timeOut the number of milliseconds to wait before giving up, 0 or negative to block until the operation is done */
220 public void setTimeOut (int timeOut) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected