2011-11-15 16 views

答えて

0

詳細はlinkに行ってください。これは同様の質問です。

+0

私は最初の質問の答えを知ってうれしいです。それは私が望むものです。適時の対応に感謝します。 – Leo

0

HttpConnectionを作成し、サーバー上でストリームを渡します。この後に従いますlink

1
  // Enable HTTP parameters 
      HttpParams sslparams = new BasicHttpParams(); 
      HttpProtocolParams.setVersion(sslparams, HttpVersion.HTTP_1_1); 
      HttpProtocolParams.setContentCharset(sslparams, HTTP.UTF_8); 

      // Register the HTTP and HTTPS Protocols. For HTTPS, register our custom SSL Factory object. 
      SchemeRegistry registry = new SchemeRegistry(); 
      registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
      registry.register(new Scheme("https",sslFactory, 443)); 

      // Create a new connection manager using the newly created registry and then create a new HTTP client 
      // using this connection manager 
      ClientConnectionManager ccm = new ThreadSafeClientConnManager(sslparams, registry); 
      httpclient = new DefaultHttpClient(ccm,sslparams); 

      HttpPost httppost = new HttpPost(url); 
      /*httppost.setEntity(new UrlEncodedFormEntity(nameValue)); 
      httppost.setEntity(new InputStreamEntity(new FileInputStream(file), file.length())); 
      httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");*/ 
      MultipartEntity entity = new MultipartEntity(); 
      //entity.addPart("fileName",); 
      entity.addPart("file", new InputStreamBody(new FileInputStream(file), ContentType.APPLICATION_OCTET_STREAM)); 
      entity.addPart("UserID", new StringBody(parameter.getUsreId())); 
      entity.addPart("UserName",new StringBody(parameter.getUserName())); 
      entity.addPart("HostName", new StringBody(parameter.getHostName())); 
      entity.addPart("ProtectionType", new StringBody(parameter.getProtectionType())); 
      entity.addPart("FolderPath", new StringBody(parameter.getFolderPath())); 
      entity.addPart("osid", new StringBody(parameter.getOsId())); 
      //entity.addPart("file", new FileBody(file,ContentType.MULTIPART_FORM_DATA)); 
      httppost.setEntity(entity); 
      //httppost.setEntity(new StringEntity(file)); 
      //httppost.setHeader("Content-Type", "text/xml"); 

      HttpParams httpparams = new BasicHttpParams(); 
      HttpConnectionParams.setConnectionTimeout(httpparams, 15000); 
      HttpConnectionParams.setSoTimeout(httpparams, 30000); 
      httppost.setParams(httpparams); 
      HttpResponse response = httpclient.execute(httppost); 
関連する問題