酷酷七友软件定做 酷酷七友软件

软件开发

新浪改图片源码c#

新浪改图片源码c#

很多人问我怎么post上传 图片,我总结了一下,干脆贴出代码来吧,很清晰的思路,不  懂的Q:302777528 byError网络科技

request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.ContentType = "multipart/form-data; boundary=---------------------------7dc3d8cb0282";
      
            request.Referer = this.reffer;
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1";// Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
            request.Method = "POST";
            request.Headers.Add("Cookie: " + this.cokie);
            StringBuilder builder = new StringBuilder();
          
            builder.Append(str + "\r\n");
                       builder.Append(Environment.NewLine);
            builder.Append("avatar" + "\r\n");

            builder.Append(str + "\r\n");
                     builder.Append(Environment.NewLine);
            builder.Append("1" + "\r\n");

            builder.Append(str);
            builder.Append("\r\n");
                     builder.Append("\r\n");
            builder.Append("Content-Type: ");
            builder.Append("image/jpeg");
            builder.Append("\r\n\r\n");
            string s = builder.ToString();
            byte[] bytes = Encoding.UTF8.GetBytes(s);
            byte[] buffer = Encoding.ASCII.GetBytes("\r\n" + str + "--\r\n");
            try
            {
                FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
                 long num = (bytes.Length + stream.Length) + buffer.Length;
                request.ContentLength = num;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                byte[] buffer3 = myReader.ReadBytes((int)stream.Length);  
                requestStream.Write(buffer3, 0, buffer3.Length);
               
                 requestStream.Write(buffer, 0, buffer.Length);

}

byerror