免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Java 模擬并發(fā)訪問
  1. import java.io.DataInputStream;         
  2. import java.io.DataOutputStream;             
  3. import java.net.HttpURLConnection;         
  4. import java.net.URL;             
  5. import java.util.Map;    
  6. import java.util.Properties;   
  7.   
  8. public class NetUtils   
  9. {   
  10.        
  11.     public static final String CHARACTER_ENCODING = "UTF-8";         
  12.   public static final String PATH_SIGN = "/";         
  13.   public static final String METHOD_POST = "POST";         
  14.   public static final String METHOD_GET = "GET";         
  15.   public static final String CONTENT_TYPE = "Content-Type";         
  16.       
  17.   /**      
  18.    * 以POST方式向指定地址發(fā)送數(shù)據(jù)包請求,并取得返回的數(shù)據(jù)包      
  19.    *       
  20.    * @param urlString      
  21.    * @param requestData      
  22.    * @return 返回數(shù)據(jù)包      
  23.    * @throws Exception      
  24.    */        
  25.   public static byte[] requestPost(String urlString, byte[] requestData)         
  26.           throws Exception   
  27.   {         
  28.       Properties requestProperties = new Properties();         
  29.       requestProperties.setProperty(CONTENT_TYPE,         
  30.               "application/octet-stream; charset=utf-8");         
  31.       
  32.       return requestPost(urlString, requestData, requestProperties);         
  33.   }         
  34.   
  35.   /**      
  36.    * 以POST方式向指定地址發(fā)送數(shù)據(jù)包請求,并取得返回的數(shù)據(jù)包      
  37.    *       
  38.    * @param urlString      
  39.    * @param requestData      
  40.    * @param requestProperties      
  41.    * @return 返回數(shù)據(jù)包      
  42.    * @throws Exception      
  43.    */        
  44.   public static byte[] requestPost(String urlString, byte[] requestData,         
  45.           Properties requestProperties) throws Exception   
  46.   {   
  47.       byte[] responseData = null;         
  48.       HttpURLConnection con = null;         
  49.       
  50.       try {         
  51.           URL url = new URL(urlString);         
  52.           con = (HttpURLConnection) url.openConnection();         
  53.           //設置請求屬性   
  54.           if ((requestProperties != null) && (requestProperties.size() > 0))   
  55.           {         
  56.               for (Map.Entry<Object, Object> entry : requestProperties.entrySet())   
  57.               {         
  58.                   String key = String.valueOf(entry.getKey());         
  59.                   String value = String.valueOf(entry.getValue());         
  60.                   con.setRequestProperty(key, value);         
  61.               }         
  62.           }         
  63.       
  64.           con.setRequestMethod(METHOD_POST); // 置為POST方法         
  65.       
  66.           con.setDoInput(true); // 開啟輸入流         
  67.           con.setDoOutput(true); // 開啟輸出流         
  68.       
  69.           // 如果請求數(shù)據(jù)不為空,輸出該數(shù)據(jù)。         
  70.           if (requestData != null)   
  71.           {         
  72.               DataOutputStream dos = new DataOutputStream(con.getOutputStream());         
  73.               dos.write(requestData);   
  74.               dos.flush();         
  75.               dos.close();         
  76.           }         
  77.       
  78.           int length = con.getContentLength();         
  79.           // 如果回復消息長度不為-1,讀取該消息。         
  80.           if (length != -1)   
  81.           {         
  82.               DataInputStream dis = new DataInputStream(con.getInputStream());         
  83.               responseData = new byte[length];         
  84.               dis.readFully(responseData);         
  85.               dis.close();         
  86.           }         
  87.       }   
  88.       catch (Exception e)   
  89.       {         
  90.           throw e;         
  91.       }   
  92.       finally  
  93.       {         
  94.           if (con != null)   
  95.           {         
  96.               con.disconnect();         
  97.               con = null;         
  98.           }         
  99.       }         
  100.       return responseData;         
  101.   }         
  102.   
  103. }  
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
將輸出流(OutputStream)轉(zhuǎn)化為輸入流(InputStream)的方法(一)
java中base64
實現(xiàn) Android 應用在開機時自啟動
字節(jié)流與字符流的區(qū)別詳解
Java網(wǎng)絡編程
JAVA上DES加密算法的實現(xiàn)用例
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服