| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1788 人关注过本帖
标题:求代码解释
只看楼主 加入收藏
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
结帖率:76.47%
收藏
 问题点数:0 回复次数:0 
求代码解释
程序代码:
  string url = "http://" + Request.Url.Authority + "/Open/TESTImgProcess/Add/"+type;

            double timeStamp = ConvertToUnixTimestamp(DateTime.Now);

           // string token = CalculateMD5Hash(appKey + '+' + timeStamp + '+' + appSecret);

            string path = Server.MapPath("~/Files/Current/TEST.jpg");


            string result = "";

            string boundary = "--------------------" + DateTime.Now.Ticks.ToString("x");

            byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

            

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            req.ContentType = "multipart/form-data;boundary=" + boundary;

            req.Method = "POST";

            Stream rs = req.GetRequestStream();

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("imgid", "test");
           

            string formdataTemplate = "Content-Disposition:form-data;name=\"{0}\"\r\n\r\n{1}";

            foreach (var item in dic)
            {
                rs.Write(boundaryBytes, 0, boundaryBytes.Length);

                string formItem = string.Format(formdataTemplate, item.Key, item.Value);

                byte[] formItemBytes = System.Text.Encoding.UTF8.GetBytes(formItem);

                rs.Write(formItemBytes, 0, formItemBytes.Length);
            }

            rs.Write(boundaryBytes, 0, boundaryBytes.Length);

            string headerTemplate = "Content-Disposition:form-data;name=\"{0}\";filename=\"{1}\"\r\nContent-Type:{2}\r\n\n";

            string header = string.Format(headerTemplate, "image_file", "test.jpg", "image/jpeg");

            byte[] headerBytes = System.Text.Encoding.UTF8.GetBytes(header);

            rs.Write(headerBytes, 0, headerBytes.Length);

            FileStream filestream = new FileStream(path, FileMode.Open, FileAccess.Read);

            byte[] buffer = new byte[4096];

            int bytesRead = 0;
搜索更多相关主题的帖子: Write string byte url Length 
2020-01-06 13:55
快速回复:求代码解释
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037393 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved