/**
* Send a GET request
*
* @ Param URL
* @ Return jsonobject
*/
Public static string getajaxdatafromurlforsms (string URL ){
Long begin = system. currenttimemillis ();
Log.info ("Request:" + URL );
String result = NULL;
Bufferedreader RD = NULL;
Try {
URL u = new URL (URL );
Inputstream is = U. openstream ();
RD = new bufferedreader (New inputstreamreader (is, "UTF-8 "));
Stringbuffer sb = new stringbuffer ();
String line;
While (line = RD. Readline ())! = NULL ){
SB. append (line );
}
Long end = system. currenttimemillis ();
Log.info ("response [" + (end-begin) + "]:" + sb. tostring ());
Result = sb. tostring ();
} Catch (malformedurlexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
} Finally {
If (RD! = NULL ){
Try {
Rd. Close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
}
Return result;
}
/**
* @ Return xmldata
*/
Public static document getxmldatafromurl (string URL ){
Long begin = system. currenttimemillis ();
Log.info ("Request:" + URL );
Saxbuilder = new saxbuilder ();
Document Doc = NULL;
Try {
URL u = new URL (URL );
Inputstream in = U. openstream ();
Doc = saxbuilder. Build (in );
} Catch (exception e ){
E. printstacktrace ();
}
If (log. isinfoenabled ()){
Long end = system. currenttimemillis ();
Xmloutputter outp = new xmloutputter ();
Log.info ("response [" + (end-begin) + "]:" + outp. outputstring (DOC ));
}
Return Doc;
}
/**
* Send a GET request
*
* @ Param URL
* URL
* @ Return jsonobject
*/
Public static jsonobject getjsondatafromurl (string URL ){
Long begin = system. currenttimemillis ();
Log.info ("Request:" + URL );
Jsonobject jsonobj = NULL;
Bufferedreader RD = NULL;
Try {
URL u = new URL (URL );
Inputstream is = U. openstream ();
RD = new bufferedreader (New inputstreamreader (is, "UTF-8 "));
Stringbuffer sb = new stringbuffer ();
String line;
While (line = RD. Readline ())! = NULL ){
SB. append (line );
}
Long end = system. currenttimemillis ();
Log.info ("response [" + (end-begin) + "]:" + sb. tostring ());
Jsonobj = new jsonobject (sb. tostring ());
} Catch (malformedurlexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
} Catch (jsonexception e ){
E. printstacktrace ();
} Finally {
If (RD! = NULL ){
Try {
Rd. Close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
}
Return jsonobj;
}
/**
* Send a POST request
*
* @ Param URL
* URL address Params Parameters
* @ Return jsonobject
*/
Public static jsonobject getjsondatafromurl (string URL, string Params ){
Long begin = system. currenttimemillis ();
Log.info ("Request:" + URL );
Jsonobject jsonobj = NULL;
Httpurlconnection huc = NULL;
Bufferedreader in = NULL;
Inputstreamreader ISR = NULL;
Inputstream is = NULL;
Stringbuffer sb = new stringbuffer (333 );
Try {
URL u = new URL (URL );
Huc = (httpurlconnection) U. openconnection ();
Huc. setrequestmethod ("Post ");
Huc. setdooutput (true );
Huc. getoutputstream (). Write (Params. getbytes ("UTF-8 "));
Huc. getoutputstream (). Flush ();
Huc. getoutputstream (). Close ();
Is = huc. getinputstream ();
ISR = new inputstreamreader (is, "UTF-8 ");
In = new bufferedreader (ISR );
String line = NULL;
While (line = in. Readline ())! = NULL ){
SB. append (line );
}
Long end = system. currenttimemillis ();
Log.info ("response [" + (end-begin) + "]:" + sb. tostring ());
Jsonobj = new jsonobject (sb. tostring ());
} Catch (malformedurlexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
} Catch (jsonexception e ){
E. printstacktrace ();
} Finally {
Try {
Huc. Disconnect ();
Is. Close ();
ISR. Close ();
In. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}
Return jsonobj;
}