上传文件到服务器,在Windows Mobile C#项目 [英] Upload file to server in Windows mobile C# project
问题描述
我们有服务器和Windows Mobile设备的设置作为客户端。在服务器脚本CSI准备好接受来自客户端的单个文件。
We have a setup of server and windows mobile device as a client. In server CSI script ready to accept single file from client.
在台式机,我们有使用WebClient.UploadFile方法上载文件到服务器,但是,在Windows Mobile,这不是实施,到现在我们还没有发现任何其他方法来实现相同的。
In Desktop we have use WebClient.UploadFile method to upload file to server, but in windows mobile this isn't implemented, till now we haven't found any alternative method to achieve same.
在此先感谢。
Ramanand
Thanks in advance. Ramanand
推荐答案
在使用.NET Compact Framework的,你可以使用的 System.Net.HttpWebRequest
代替msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx nofollow的 Web客户端
,这是不支持.NET CF.
When using the .NET Compact Framework, you can use System.Net.HttpWebRequest
instead of WebClient
, which isn't supported on .NET CF.
由于 Web客户端
是在的HttpWebRequest
的基础上实现,你可以做一切与的HttpWebRequest
,您可以用 Web客户端
,尽管有更多的代码。
Since WebClient
is implemented on top of HttpWebRequest
, you can do everything with HttpWebRequest
that you can with WebClient
, albeit with more code.
例如,一个URL的内容下载到一个字符串,你可以使用此代码:
For example, to download the contents of a URL into a string, you can use this code:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
string html;
using (var r = request.GetResponse().GetResponseStream())
{
using(var r2 = (TextReader)new StreamReader(r))
{
html = r2.ReadToEnd();
}
}
这篇关于上传文件到服务器,在Windows Mobile C#项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!