Upload file to server in Windows mobile C# project

狂风中的少年 提交于 2020-01-01 18:14:07

问题


We have a setup of server and windows mobile device as a client. In server CSI script ready to accept single file from client.

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.

Thanks in advance. Ramanand


回答1:


When using the .NET Compact Framework, you can use System.Net.HttpWebRequest instead of WebClient, which isn't supported on .NET CF.

Since WebClient is implemented on top of HttpWebRequest, you can do everything with HttpWebRequest that you can with WebClient, albeit with more code.

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(); 
        } 
    } 



回答2:


You should be able to use the method in this post, you could maybe do some refactoring to fit your purpose better.
Upload files with HTTPWebrequest (multipart/form-data)



来源:https://stackoverflow.com/questions/1740375/upload-file-to-server-in-windows-mobile-c-sharp-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!