Ext.: http://blog.csdn.net/gzh0222/article/details/7711281
Using the Java VUser implementation, send the GZIP compressed JSON format.
/** LoadRunner Java script. (Build: _build_number_) * * Script Description: **/import lrapi.lr;import java.io.*; import Java.io.bufferedreader;import java.io.bytearrayinputstream;import java.io.ByteArrayOutputStream; Import Java.io.ioexception;import Java.io.inputstreamreader;import Java.io.inputstream;import Java.util.zip.gzipinputstream;import Java.util.zip.gzipoutputstream;import Org.apache.http.header;import Org.apache.http.httpentity;import Org.apache.http.httpresponse;import Org.apache.http.client.httpclient;import Org.apache.http.client.clientprotocolexception;import Org.apache.http.client.methods.httppost;import Org.apache.http.entity.inputstreamentity;import org.apache.http.impl.client.DefaultHttpClient; Public classactions{ Public intinit () throws Throwable {return 0;}//End of Init Public intaction () throws Throwable {String foo="{\ "job_id\": 93044,\ "client_id\": 1009,\ "version\": \ "10001\", \ "dev_type\": 1,\ "app_guid\": \ "1\"}"; HttpResponse response; HttpClient HttpClient=Newdefaulthttpclient (); HttpPost HttpPost=NewHttpPost ("Http://10.10.10.10:61013/proxy/c/job/detail.json"); Httppost.setheader ("Content-type","Application/json; Charset=utf-8"); Httppost.setheader ("accept-encoding","gzip"); byte[] Bgzip =gzip (foo); System. out. println (Bgzip.length); Inputstreamentity httpentity=NewInputstreamentity (NewBytearrayinputstream (bgzip), bgzip.length); Httpentity.setchunked (true); Httppost.setentity (httpentity); Lr.start_transaction ("Send"); Response=Httpclient.execute (HttpPost); Httppost.setentity (httpentity); intHttpcode =response.getstatusline (). Getstatuscode (); System. out. println (Httpcode); Httpentity Entity=response.getentity (); Header Header= Response.getfirstheader ("Content-type"); System. out. println (header); InputStream InputStream=entity.getcontent (); InputStream=NewGzipinputstream (InputStream); Lr.end_transaction ("Send", LR. AUTO); InputStreamReader ISR=NewInputStreamReader (InputStream,"Utf-8");//set the encoding format of the read stream, custom encodingBufferedReader br =NewBufferedReader (ISR); StringBuffer SB=NewStringBuffer (); String TEMPBF; while((TEMPBF = Br.readline ())! =NULL) {sb.append (TEMPBF); Sb.append ("\ r \ n"); } String HTML=sb.tostring (); System. out. println (HTML); Isr.close (); Inputstream.close (); return 0;}//End of Action Public Static byte[] gzip (String foo) {Bytearrayoutputstream BAOs=NewBytearrayoutputstream (); Gzipoutputstream Gzos=NULL; Try{Gzos=NewGzipoutputstream (BAOs); Gzos.write (Foo.getbytes ("UTF-8")); } Catch(IOException e) {//TODO auto-generated Catch blocke.printstacktrace ();} finally { if(Gzos! =NULL)Try{Gzos.close ();}Catch(IOException ignore) {};} returnBaos.tobytearray (); } Public intEnd () throws Throwable {return 0;}//End of End}