zoukankan      html  css  js  c++  java
  • HttpWebRequest 方式提交文件数据以图片为例

    public void StartPing1(string pingURL)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pingURL);
                FileStream fs = new FileStream(@"D:\111.jpg", FileMode.Open, FileAccess.Read);
                Byte[] bytes = new Byte[10240];
                request.Method = "POST";
                request.Proxy = null;
                //request.Headers.Add("XXX", "XXX");
                request.ContentType = "application/octet-stream";
                Stream dataStream = request.GetRequestStream();
                int count = fs.Read(bytes, 0, 10240);
                while (count != 0)
                {
                    dataStream.Write(bytes, 0, count);
                    count = fs.Read(bytes, 0, 10240);
                }
                fs.Close();
                dataStream.Close();
                try
                {
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
                    string ret = sr.ReadToEnd();
                    response.Close();
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("!!!!!!ERROR!!!!!!!!" + ex.ToString() + "!!!!!!!!ERROR!!!!!!!!");
                }
            }
    

      

    ---下面是服务器端接收方法:

    加载事件中:
    /* 
                //StartPing1 方法 传送文件的
                System.Drawing.Image postImage = System.Drawing.Image.FromStream(Request.InputStream);
                System.Drawing.Bitmap bitmap_b = new System.Drawing.Bitmap(postImage);
                string Opath = @"D:\";
                string photoname = DateTime.Now.Ticks.ToString();
                bitmap_b.Save(Opath + "\\" + photoname + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                Response.Write("<?xml version=\"1.0\"?><params><title>OK</title></params>");
                 * */
    

      

  • 相关阅读:
    HDU-5818-Joint Stacks
    蓝桥杯-2016CC-卡片换位
    HDU-2255-奔小康赚大钱(KM算法)
    蓝桥杯-PREV31-小朋友排队
    crypto.js加密传输
    js之对象
    LigerUi之ligerMenu 右键菜单
    关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
    设置js的ctx
    AngularJS简单例子
  • 原文地址:https://www.cnblogs.com/soundcode/p/2966274.html
Copyright © 2011-2022 走看看