android 如何使用 webservices 实现文件上传下载 呀,那位高手指点下!!

解决方案 »

  1.   

    这个我前两天刚做过,你可以到我的blog去看看,我配置了一个可以将txt文档上传到URI为your mail的邮箱里面作为草稿,这样实现了文件的上传,至于下载的功能,可以参考blog内容!
      

  2.   

    使用Ksoap webservices 的方式 上传 和 下载不是用Connection
      

  3.   

    这个是我前两天在书上看到的例子,或许对你有点用
    例子介绍
    通过邮政编码查询该地区的天气预报,以POST发送的方式发送请求到webservicex.net站点,访问WebService.webservicex.net站点上提供查询天气预报的服务,具体信息请参考其WSDL文档,网址为:
    http://www.webservicex.net/WeatherForecast.asmx?WSDL。
    输入:美国某个城市的邮政编码。 
    输出:该邮政编码对应城市的天气预报。
    2.实现步骤如下
    (1)如果需要访问外部网络,则需要在AndroidManifest.xml文件中加入如下代码申请权限许可: 
    <!-- Permissions --> 
    <uses-permission Android:name="Android.permission.INTERNET" /> 
    (2)以HTTP POST的方式发送(注意:SERVER_URL并不是指WSDL的URL,而是服务本身的URL)。实现的代码如下所示:
    private static final String SERVER_URL = "http://www.webservicex.net/WeatherForecast. asmx/GetWeatherByZipCode"; //定义需要获取的内容来源地址
    HttpPost request = new HttpPost(SERVER_URL); //根据内容来源地址创建一个Http请求
    // 添加一个变量 
    List <NameValuePair> params = new ArrayList <NameValuePair>(); 
    // 设置一个华盛顿区号
    params.add(new BasicNameValuePair("ZipCode", "200120"));  //添加必须的参数
    request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); //设置参数的编码
    try { 
    HttpResponse httpResponse = new DefaultHttpClient().execute(request); //发送请求并获取反馈
    // 解析返回的内容
    if(httpResponse.getStatusLine().getStatusCode() != 404)  

      String result = EntityUtils.toString(httpResponse.getEntity()); 
      Log.d(LOG_TAG, result); 

    } catch (Exception e) { 
    Log.e(LOG_TAG, e.getMessage()); } 
     代码解释:
    如上代码使用Http从webservicex获取ZipCode为“200120”(美国WASHINGTON D.C)的内容,其返回的内容如下:
    <WeatherForecasts xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns="http://www.webservicex.net"> 
      <Latitude>38.97571</Latitude> 
      <Longitude>77.02825</Longitude> 
      <AllocationFactor>0.024849</AllocationFactor> 
      <FipsCode>11</FipsCode> 
      <PlaceName>WASHINGTON</PlaceName> 
      <StateCode>DC</StateCode> 
      <Details> 
        <WeatherData> 
          <Day>Saturday, April 25, 2009</Day>      <WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</WeatherImage> 
          <MaxTemperatureF>88</MaxTemperatureF> 
          <MinTemperatureF>57</MinTemperatureF> 
          <MaxTemperatureC>31</MaxTemperatureC> 
          <MinTemperatureC>14</MinTemperatureC> 
        </WeatherData> 
        <WeatherData> 
          <Day>Sunday, April 26, 2009</Day>       <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage> 
          <MaxTemperatureF>89</MaxTemperatureF> 
          <MinTemperatureF>60</MinTemperatureF> 
          <MaxTemperatureC>32</MaxTemperatureC> 
          <MinTemperatureC>16</MinTemperatureC> 
        </WeatherData>

      </Details> 
    </WeatherForecasts>
    这个例子演示了如何在Android中通过网络获取数据,掌握该类内容,开发者需要熟悉java.net.*,Android.net.*这两个包的内容
      

  4.   

    HTTP 的方式 谁做过啊  给指点下
      

  5.   

    我这里有一段下载歌曲的HTTP代码  ,给LZ分享一下吧try {
             //读取链接地址歌曲文件流
            URL url = new URL(uriStr);
             HttpURLConnection conn = (HttpURLConnection)   url.openConnection();       
             conn.setDoInput(true);
             conn.connect();
             InputStream is = conn.getInputStream();
            
             //创建本地保存流的文件
             File musicFile = new File("/sdcard/", decode);
            
             FileOutputStream fos = new FileOutputStream(musicFile);
            
             byte[] bt = new byte[1024];         
             int    i = 0;
            
                while ( (i = is.read(bt)) > 0 ) 
                {
                    fos.write(bt, 0, i);
                }
                Log.d(TAG, "stop write");
                
                fos.close();
                is.close();
                      
                
                
            } catch(IOException e) { }
      

  6.   

    谁有andriod的视频 我想学andriod   有的麻烦传我邮箱  [email protected]   谢谢了!