예제 #1
0
 /**
  * 获取真实文件名(xx.后缀),通过网络获取.
  *
  * @throws IOException
  */
 public void testGetRealFileName() throws IOException {
   SaLogUtils.d(TAG, "获取真实文件名(xx.后缀),通过网络获取.");
   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.getRealFileName(mHttpURLConnection);
 }
예제 #2
0
  /**
   * 获取真实文件名(xx.后缀),通过网络获取.
   *
   * @throws IOException
   */
  @SuppressWarnings("deprecation")
  public void testHttpResponseGetRealFileName() {
    SaLogUtils.d(TAG, "获取真实文件名(xx.后缀),通过网络获取.");
    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.getRealFileName(httpResponse);
      } else {

      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }