首页 新闻 会员 周边 捐助

c#模拟 post提交大数据,就是不行,求助!!

0
悬赏园豆:10 [待解决问题]
string data = string.Empty;
            System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(@"C:\Users\yafa2\Desktop\11.jpg");
            using (MemoryStream ms1 = new MemoryStream())
            {
                bmp1.Save(ms1, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr1 = new byte[ms1.Length];
                ms1.Position = 0;
                ms1.Read(arr1, 0, (int)ms1.Length);
                ms1.Close();
                data = Convert.ToBase64String(arr1);
            }
            Encoding encoding = System.Text.Encoding.Default;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.9.100.36:5012/UpDownFile.asmx/UpImgByApp");
           
            System.Text.StringBuilder builder = new System.Text.StringBuilder(); 
            builder.AppendFormat("{0}={1}&", "data",data);//此处是图片的64位字符编码,但是会超长,请问怎么解决,
            builder.AppendFormat("{0}={1}&", "fileName", "110000200069_201908151740218.jpg");
            builder.AppendFormat("{0}={1}", "id", "110000200069_201908151740281");

            byte[] postData = System.Text.Encoding.UTF8.GetBytes(builder.ToString());

            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.Timeout = 1000 * 30;
            req.ContentLength = postData.Length;

            using (System.IO.Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(postData, 0, postData.Length);
                reqStream.Close();
            }
            System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse();
            System.IO.Stream stream = resp.GetResponseStream();
            //获取响应内容
            using (System.IO.StreamReader reader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8))
            {
                data = reader.ReadToEnd();
            }
            MessageBox.Show(data);

在post man 中没问题,为什么在c#中 就是那个data超长呢??postman用的是body方式提的,怎么用c#body提交?? 我试过了form data方式不行

IDOER的主页 IDOER | 初学一级 | 园豆:19
提问于:2019-08-16 13:36
< >
分享
所有回答(2)
0

你改成json格式提交看看。我记得我们做的手机端提交图片,几张手机图片可以一下提交上去。也是编码一样可以提交。就是微信接口的拍照图片格式,好像是base64编码。

gw2010 | 园豆:1487 (小虾三级) | 2019-08-16 16:04
0

教你一招一模一样的复制方式:1.开fiddler,然后raw;然后c# 把raw复制,之后用 tcp 写进入去。

花飘水流兮 | 园豆:13617 (专家六级) | 2019-08-17 15:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册