问题描述
packagecom.thinkit.test;importjava.io.BufferedInputStream;importjava.io.DataOutputStream;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.IOException;importjava.io.InputStream;importjava.net.HttpURLConnection;importjava.net.URL;importjava.util.ArrayList;importjava.util.List;publicclassASRInterTest{publicStringDoAction(StringInFileName)throwsException{//DataOutputStreamout=null;Stringcontent="";StringUserID="userid";StringSequenceID="1";StringHash="Hash";StringSessionID="ser";StringurlStr="http://101.95.48.190/yuyin/bstqyzj";List<BufferedInputStream>data=newArrayList<BufferedInputStream>();System.out.print("nASRInterTest=====InFileName=====>"+InFileName);FileInputStreamoutSTr=null;try{outSTr=newFileInputStream(newFile(InFileName));System.out.print("noutSTr"+outSTr.toString());}catch(FileNotFoundExceptione1){e1.printStackTrace();}BufferedInputStreamBuff=newBufferedInputStream(outSTr);data.add(Buff);URLurl=newURL(urlStr);HttpURLConnectionconn=(HttpURLConnection)url.openConnection();conn.setDoInput(true);conn.setDoOutput(true);conn.setUseCaches(false);conn.setRequestMethod("POST");conn.setRequestProperty("Buss-Type","bst-qyzj");conn.setRequestProperty("UserID",UserID);conn.setRequestProperty("SessionID",SessionID);conn.setRequestProperty("sequenceID",SequenceID);conn.setRequestProperty("isEnd","0");conn.setRequestProperty("AUE","raw");conn.setRequestProperty("AUF","16000");conn.setRequestProperty("content-Type","application/audio");conn.setRequestProperty("VER","1.0");conn.setRequestProperty("HASH",Hash);if(data.size()>0){DataOutputStreamds=newDataOutputStream(conn.getOutputStream());//out=newDataOutputStream(conn.getOutputStream());intidx=1;intenc_bits=1;intiSize=Buff.available();intfileLen=0;try{fileLen=outSTr.available();}catch(IOExceptione1){e1.printStackTrace();}if(enc_bits>0){byte[]bBuffer=newbyte[iSize];try{enc_bits=Buff.read(bBuffer);System.out.println("nenc:"+enc_bits);}catch(IOExceptione){e.printStackTrace();}ds.write(bBuffer,0,enc_bits);}ds.flush();//out.flush();}System.out.print("nconn.getResponseCode()=======>"+conn.getResponseCode());if(conn.getResponseCode()==200){InputStreamis=conn.getInputStream();byte[]outbyte=newbyte[is.available()];is.read(outbyte);System.out.print("nis.available()=======>"+is.available());for(inti=0;i<is.available();i++){content+=outbyte[i];}//content=is.toString();}conn.disconnect();System.out.print("ncontent=======>"+content);returncontent;}}
解决方案
解决方案二:
你自己先测试一下,