Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.Iterator;
import uk.org.retep.annotations.NoInstance;
/**
* Convert an HTTP header to a JSONObject and back.
* @author JSON.org
* @version 2008-09-18
*/
@NoInstance
public class HTTP
{
private HTTP()
{
}
/** Carriage return/line feed. */
public static final String CRLF = "\r\n";
/**
* Convert an HTTP header string into a JSONObject. It can be a request
* header or a response header. A request header will contain
*
* It does no further checking or conversion. It does not parse dates.
* It does not do '%' transforms on URLs.
* @param string An HTTP header string.
* @return A JSONObject containing the elements and attributes
* of the XML string.
* @throws JSONException
*/
public static JSONObject toJSONObject( String string )
throws JSONException
{
JSONObject o = new JSONObject();
HTTPTokener x = new HTTPTokener( string );
String t;
t = x.nextToken();
if( t.toUpperCase().startsWith( "HTTP" ) )
{
// Response
o.put( "HTTP-Version", t );
o.put( "Status-Code", x.nextToken() );
o.put( "Reason-Phrase", x.nextTo( '\0' ) );
x.next();
}
else
{
// Request
o.put( "Method", t );
o.put( "Request-URI", x.nextToken() );
o.put( "HTTP-Version", x.nextToken() );
}
// Fields
while( x.more() )
{
String name = x.nextTo( ':' );
x.next( ':' );
o.put( name, x.nextTo( '\0' ) );
x.next();
}
return o;
}
/**
* Convert a JSONObject into an HTTP header. A request header must contain
*