JavaXT
|
|||||||
Response ClassUsed to process the response from an HTTP server.
ConstructorsThere are no public constructors.Public MethodsgetURL( ) returns java.net.URL Returns the url used to connect to the server. Note that this URL may differ from the one used to instantiate the Request object. This only occurs when the server returns a redirect code and the maximum number of redirects is greater than 0. See Request.setNumRedirects(). getHeaders( ) returns java.util.Map<String, java.util.List<String>> Returns key/value map representing all the HTTP headers returned from the server. getHeaders( String headerName ) returns String[] Returns an array of values associated with a given key found in the HTTP headers returned from the server. getHeader( String headerName ) returns String Returns the value of a given key in the HTTP header. Returns null if the header is not found in the response.
getStatus( ) returns int Returns the HTTP status code extracted from the first line in the response header. If the client fails to connect to the server, a value of -1 is returned. getMessage( ) returns String Returns the status message found in the first line in the response header. getCharacterEncoding( ) returns String Returns the name of the character encoding used in the body of this response as specified in the "Content-Type" header. For example, the following "Content-Type" header specifies "UTF-8" character encoding: Content-Type: text/html; charset=utf-8This method returns a null if the response does not specify a character encoding. getInputStream( ) returns InputStream Returns the body of the http response as an input stream. No distinction is made between "normal" responses (e.g. status code 200) and error responses (e.g. 404). Sample Usage:
java.io.InputStream inputStream = response.getInputStream(); byte[] b = new byte[1024]; int x=0; while ( (x = inputStream.read(b)) != -1) { //Do something! Example: outputStream.write(b,0,x); } inputStream.close(); getText( ) returns String Used read through the entire response stream and cast it to a string. The string is encoded using the character set specified in the "Content-Type" header as returned by the getCharacterEncoding() method. Defaults to "UTF-8" if no character set is defined. getText( String charsetName ) returns String Used read through the entire response stream and cast it to a string. WARNING: This method will never throw an error.
getJSONObject( ) returns javaxt.json.JSONObject Used read through the entire response stream and returns a JSON object getJSONArray( ) returns javaxt.json.JSONArray Used read through the entire response stream and returns a JSON array getXML( ) returns org.w3c.dom.Document Used read through the entire response stream and converts it to an xml DOM document. getImage( ) returns javaxt.io.Image Used read through the entire response stream and returns an Image. getBytes( ) returns ByteArrayOutputStream Used read through the entire response stream and returns a raw byte array (ByteArrayOutputStream). Note that this method does not automatically decompress the response if the data is compressed. Use the Response.getBytes(true) method to automatically decompress the response. getBytes( boolean deflate ) returns ByteArrayOutputStream Used read through the entire response stream and returns a byte array ByteArrayOutputStream.
toString( ) returns String Returns the raw response headers returned from the server. Use the getText() method to get response body as a String. |