http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3926|回复: 7

[其他] 飞哥 还是上传图片有问题 这次贴出来post的请求图片

[复制链接]
发表于 2014-3-3 14:56:30 | 显示全部楼层 |阅读模式
看下header:
header.jpg

看下发送的包:
未标题-1 拷贝.png


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-3-3 15:32:48 | 显示全部楼层
什么问题呀!
 楼主| 发表于 2014-3-4 14:33:49 | 显示全部楼层

post提交不上去的
发表于 2014-3-4 14:36:00 | 显示全部楼层

呵呵,你能一下说清楚吧,提交不上是什么个情况,提示什么,或者提供下代码看看
 楼主| 发表于 2014-3-4 14:40:21 | 显示全部楼层
[C#] 纯文本查看 复制代码
 //long length = 0;
            string debug = "";
            if (boundary == "----------------------------")
                boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
            WebResponse webResponse2 = null;
            StreamReader reader2 = null;
            HttpWebResponse response = null;

            HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest2.ContentType = "multipart/form-data; boundary=" +
            boundary;
            httpWebRequest2.CookieContainer = cookie;
            httpWebRequest2.Method = "POST";
            httpWebRequest2.KeepAlive = true;
            httpWebRequest2.Credentials = System.Net.CredentialCache.DefaultCredentials;
            httpWebRequest2.Accept = "*/*";//设置标头
            httpWebRequest2.KeepAlive = true;
            httpWebRequest2.Referer = "XXXXX";
            httpWebRequest2.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
            httpWebRequest2.Headers.Add("Accept-Language", "zh-CN");//设置标头
            httpWebRequest2.Headers.Add("Cache-Control", "no-cache");//设置标头
            try
            {

                Stream memStream = new System.IO.MemoryStream();

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


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

                foreach (string key in nvc.Keys)
                {
                    string formitem = string.Format(formdataTemplate, key, nvc[key]); debug += formitem;
                    byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
                    memStream.Write(formitembytes, 0, formitembytes.Length);
                }


                memStream.Write(boundarybytes, 0, boundarybytes.Length);

                string headerTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"; fname=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";

                for (int i = 0; i < files.Length; i++)
                {

                    //string header = string.Format(headerTemplate, "file" + i, files[i]);
                    string header = string.Format(headerTemplate, "Filedata", System.IO.Path.GetFileName(files[i]));
                    debug += header;
                    byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);

                    memStream.Write(headerbytes, 0, headerbytes.Length);


                    FileStream fileStream = new FileStream(files[i], FileMode.Open,
                    FileAccess.Read);
                    byte[] buffer = new byte[1024];

                    int bytesRead = 0;

                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        debug += System.Text.Encoding.Default.GetString(buffer);
                        memStream.Write(buffer, 0, bytesRead);

                    }

                    fileStream.Close();
                }
                //name="Upload"
                string Uploads = "--" + boundary +
                "\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n";
                debug = debug + Uploads;
                memStream.Write(System.Text.Encoding.UTF8.GetBytes(Uploads), 0, Uploads.Length);
                // string temstr = System.Text.Encoding.Default.GetString(boundarybytes);    // End boundary
                debug = debug + "--cvaxveuvmflnnomwapfghqjhlpfcrkyx--";
                byte[] tem = System.Text.Encoding.UTF8.GetBytes("--cvaxveuvmflnnomwapfghqjhlpfcrkyx--");
                memStream.Write(tem, 0, tem.Length);

                httpWebRequest2.ContentLength = memStream.Length;

                Stream requestStream = httpWebRequest2.GetRequestStream(); //PostingStream

                memStream.Position = 0;
                byte[] tempBuffer = new byte[memStream.Length];
                memStream.Read(tempBuffer, 0, tempBuffer.Length);

                //StreamReader sr = new StreamReader(requestStream, Encoding.UTF8);
                //StringBuilder strBuilder = new StringBuilder();
                //while (-1 != sr.Peek())
                //{
                //    strBuilder.Append(sr.ReadLine() + "\r\n ");
                //}
                //string resu=strBuilder.ToString();

                memStream.Close();
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
                requestStream.Close();

                webResponse2 = httpWebRequest2.GetResponse();

                response = (HttpWebResponse)webResponse2;

                //StreamReader SR = new StreamReader(response.GetResponseStream());


                Stream stream2 = webResponse2.GetResponseStream();
                reader2 = new StreamReader(stream2);

                debug += "\r\n提交后Cookie:" + cookie.GetCookieHeader(new Uri(url));//拼接提交后cookie,用于分析
                debug = debug + "\r\n\r\n=================================================\r\n\r\n本次请求:" + url + " 响应结果:" + response.StatusCode + "\r\n\r\n" + debug + "\r\n" + httpWebRequest2.CookieContainer.GetCookieHeader(new Uri(url)) + "\r\nrequest:\r\n" + httpWebRequest2.Headers.ToString() + "\r\nresponse:\r\n" + response.Headers.ToString() + "\r\n\r\n=================================================\r\n\r\n";
                System.IO.File.WriteAllText("aa.txt", debug);

                return reader2.ReadToEnd();
            }
            catch
            {
                return "";
            }
            finally
            {
                if (webResponse2 != null)
                {
                    webResponse2.Close();
                    webResponse2 = null;
                }
                if (reader2 != null)
                    reader2.Close();
                httpWebRequest2 = null;

            }
发表于 2014-3-4 15:10:55 | 显示全部楼层
luocaihuang 发表于 2014-3-4 14:40
[mw_shl_code=csharp,true] //long length = 0;
            string debug = "";
            if (bounda ...

链接发来。
 楼主| 发表于 2014-3-4 15:26:04 | 显示全部楼层
本帖最后由 luocaihuang 于 2014-3-4 15:35 编辑

http://upload.alibaba.com/fileupload.html

每个地方post提交还不一样的! 这里链接照样可以上传的
 楼主| 发表于 2014-3-6 09:24:00 | 显示全部楼层
站长苏飞 发表于 2014-3-4 14:36
呵呵,你能一下说清楚吧,提交不上是什么个情况,提示什么,或者提供下代码看看

(function(){var returnMsg = new AE.widget.message();returnMsg.init();returnMsg.pushMsg('Can not Parse Data!','null','1');return returnMsg;})();  飞哥咋办呢  老提示不能解析
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-24 02:12

© 2014-2021

快速回复 返回顶部 返回列表