wince如何实现上传图片到web服务器,我使用的是HttpWebRequest?急求
发布网友
发布时间:2022-09-16 00:32
我来回答
共3个回答
热心网友
时间:2023-10-11 07:34
private static void UploadFile(Stream postedStream, string fileName,
2 string uploadURL, string fileGroup, string fileType,
3 string specialPath, string userName, string uploadType)
4 {
5 if (string.IsNullOrEmpty(uploadURL))
6 throw new Exception("Upload Web URL Is Empty.");
7
8 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uploadURL);
9
10 //Our method is post, otherwise the buffer (postvars) would be useless
11 webRequest.Method = WebRequestMethods.Http.Post;
12
13 // Proxy setting
14 WebProxy proxy = new WebProxy();
15 proxy.UseDefaultCredentials = true;
16 webRequest.Proxy = proxy;
17
18 //We use form contentType, for the postvars.
19 webRequest.ContentType = "application/x-www-form-urlencoded";
20
21 webRequest.Headers.Add("FileGroup", fileGroup);
22 webRequest.Headers.Add("FileType", fileType);
23 webRequest.Headers.Add("UploadType", uploadType);
24 webRequest.Headers.Add("FileName", fileName);
25 webRequest.Headers.Add("UserName", userName);
26 webRequest.Headers.Add("SpecialFolderPath", specialPath);
27
28 using (Stream requestStream = webRequest.GetRequestStream())
29 {
30 FileUtility.CopyStream(postedStream, requestStream);
31 }
32 try
33 {
34 webRequest.GetResponse().Close();
35 }
36 catch (WebException ex)
37 {
38 HttpWebResponse response = ex.Response as HttpWebResponse;
39 if (response != null)
40 {
41 throw new WebException(response.StatusDescription, ex);
42 }
43
44 throw ex;
45 }
46 catch (Exception exception)
47 {
48 throw exception;
49 }
50 }
热心网友
时间:2023-10-11 07:35
直接在代码里组织成html,往客户80端口送就行了~
热心网友
时间:2023-10-11 07:35
可以呀,把图片读取到文件里,用文件流就可以了