Пример #1
0
 /**
  * 获取文件名(.后缀),外链模式和通过网络获取.
  *
  * @throws IOException
  */
 public void testGetHttpURLConnectionCacheFileNameFromUrl() throws IOException {
   String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
   URL mUrl = new URL(url);
   HttpURLConnection mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
   mHttpURLConnection.setConnectTimeout(5 * 1000);
   mHttpURLConnection.setRequestMethod("GET");
   mHttpURLConnection.setRequestProperty(
       "Accept",
       "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
   mHttpURLConnection.setRequestProperty("Accept-Language", "zh-CN");
   mHttpURLConnection.setRequestProperty("Referer", url);
   mHttpURLConnection.setRequestProperty("Charset", "UTF-8");
   mHttpURLConnection.setRequestProperty("User-Agent", "");
   mHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
   mHttpURLConnection.connect();
   SaFileUtils.getCacheFileNameFromUrl(url, mHttpURLConnection);
 }
Пример #2
0
  /** 获取文件名(.后缀),外链模式和通过网络获取. */
  @SuppressWarnings("deprecation")
  public void testGetCacheFileNameFromUrl() {

    String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
    // HttpGet对象
    HttpGet httpGet = new HttpGet(url);
    try {
      // 取得HttpClient对象
      HttpClient httpClient = new DefaultHttpClient();
      // 请求HttpClient,取得HttpResponse
      HttpResponse httpResponse = httpClient.execute(httpGet);
      // 请求成功
      if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        SaFileUtils.getCacheFileNameFromUrl(url, httpResponse);
      } else {

      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
 /** 获取文件名(不含后缀).MD5加密之后的 */
 public void testGetMD5CacheFileNameFromUrl() {
   String url = "http://img.bbs.csdn.net/upload/201404/09/1397024929_242396.jpg";
   SaFileUtils.getCacheFileNameFromUrl(url);
 }