2.0通信之WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据
2009-06-08 22:04
337 查看
介绍
Silverlight 2.0 详解WebClient,以字符串的形式上传、下载数据;以流的方式上传、下载数据
WebClient - 将数据发送到指定的 URI,或者从指定的 URI 接收数据的类
DownloadStringAsync(Uri address, Object userToken) - 以字符串的形式下载指定的 URI 的资源
UploadStringAsync(Uri address, string data) - 以字符串的形式上传数据到指定的 URI。所使用的 HTTP 方法默认为 POST
OpenReadAsync(Uri address, Object userToken) - 以流的形式下载指定的 URI 的资源
OpenWriteAsync(Uri address, string method, Object userToken) - 打开流以使用指定的方法向指定的 URI 写入数据
在线DEMO
/article/4589581.html
示例
1、以字符串的形式和流的形式下载数据
WebClientDownload.xaml
<UserControl x:Class="Silverlight20.Communication.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgString" Margin="5" />
<ProgressBar x:Name="progressBarString" Height="20" Margin="5" Minimum="0" Maximum="100" />
</StackPanel>
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgStream" Margin="5" />
<ProgressBar x:Name="progressBarStream" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Image x:Name="img" Margin="5" />
</StackPanel>
</StackPanel>
</UserControl>
WebClientDownload.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace Silverlight20.Communication
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
WebClientUpload.xaml
<UserControl x:Class="Silverlight20.Communication.WebClientUpload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgString" Margin="5" />
<ProgressBar x:Name="progressBarString" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Button x:Name="btnString" Content="上传文件(字符串的方式)" Margin="5" Click="btnString_Click" />
</StackPanel>
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgStream" Margin="5" />
<ProgressBar x:Name="progressBarStream" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Button x:Name="btnStream" Content="上传文件(流的方式)" Margin="5" Click="btnStream_Click" />
</StackPanel>
</StackPanel>
</UserControl>
WebClientUpload.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Resources;
using System.ComponentModel;
using System.Windows.Browser;
namespace Silverlight20.Communication
Silverlight 2.0 详解WebClient,以字符串的形式上传、下载数据;以流的方式上传、下载数据
WebClient - 将数据发送到指定的 URI,或者从指定的 URI 接收数据的类
DownloadStringAsync(Uri address, Object userToken) - 以字符串的形式下载指定的 URI 的资源
UploadStringAsync(Uri address, string data) - 以字符串的形式上传数据到指定的 URI。所使用的 HTTP 方法默认为 POST
OpenReadAsync(Uri address, Object userToken) - 以流的形式下载指定的 URI 的资源
OpenWriteAsync(Uri address, string method, Object userToken) - 打开流以使用指定的方法向指定的 URI 写入数据
在线DEMO
/article/4589581.html
示例
1、以字符串的形式和流的形式下载数据
WebClientDownload.xaml
<UserControl x:Class="Silverlight20.Communication.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgString" Margin="5" />
<ProgressBar x:Name="progressBarString" Height="20" Margin="5" Minimum="0" Maximum="100" />
</StackPanel>
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgStream" Margin="5" />
<ProgressBar x:Name="progressBarStream" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Image x:Name="img" Margin="5" />
</StackPanel>
</StackPanel>
</UserControl>
WebClientDownload.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace Silverlight20.Communication
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class REST
WebClientUpload.xaml
<UserControl x:Class="Silverlight20.Communication.WebClientUpload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgString" Margin="5" />
<ProgressBar x:Name="progressBarString" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Button x:Name="btnString" Content="上传文件(字符串的方式)" Margin="5" Click="btnString_Click" />
</StackPanel>
<StackPanel Margin="5" Width="200">
<TextBox x:Name="lblMsgStream" Margin="5" />
<ProgressBar x:Name="progressBarStream" Height="20" Margin="5" Minimum="0" Maximum="100" />
<Button x:Name="btnStream" Content="上传文件(流的方式)" Margin="5" Click="btnStream_Click" />
</StackPanel>
</StackPanel>
</UserControl>
WebClientUpload.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Resources;
using System.ComponentModel;
using System.Windows.Browser;
namespace Silverlight20.Communication
相关文章推荐
- 稳扎稳打Silverlight(20) - 2.0通信之WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据
- 稳扎稳打Silverlight(20) - 2.0通信之WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据
- 稳扎稳打Silverlight(20) - 2.0通信之WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据
- 上接稳扎稳打Silverlight(20) - 2.0通信之WebClient, 以字符串的形式上传/下载数据
- WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据(转)
- spring mvc源码-》MultipartReques类-》主要是对文件上传进行的处理,在上传文件时,编码格式为enctype="multipart/form-data"格式,以二进制形式提交数据,提交方式为post方式。
- 纯vc sdk实现http post 方式上传数据到web服务器
- (总结2)WinForm中3种方式文件上传服务器:WebClient
- SilverLight学习笔记--使用WebClient实现通讯(一)(上传和下载字符串数据)
- SpringMVC整合fastdfs-client-java实现web文件上传下载
- WebClient.DownloadFileAsync实现下载网络数据-简单的下载软件
- 一步一步学Silverlight 2系列(12):数据与通信之WebClient
- HttpClient 4使用方法的几个例子(代理,StringEntity字符串数据,文件上传)(转载)
- 以Base64字符串形式上传文件——在web浏览器端使用原生Javascript及Ajax读取本地文件并发送请求到服务器
- 将上传文件以二进制形式存入数据库中,并下载数据库中的二进制数据生成对应的文件
- Nginx安装-让文件服务器fastdfs提供有web方式的上传下载功能
- 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件
- WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)
- WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)
- 在web下的 sun.net.ftp.FtpClient 的ftp上传与下载