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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 8684|回复: 7

[求助] HttpHelper模拟flash上传图片的问题

[复制链接]
发表于 2014-4-24 10:07:54 | 显示全部楼层 |阅读模式
亲们,我现在在做一个模拟发布腾讯微博的小工具,通过抓包已经可以正常登陆并发布文字微博了,现在卡在图片上传上面,微博首页上传图片用的是flash上传,用Fiddler抓包分析后模拟上传出现问题,传递的参数都和网页上传的参数一一对应,但是上传结果总是提示参数错误,麻烦高手看一下,我把源码发上来:
[C#] 纯文本查看 复制代码
/// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public string uploadImage()
        {
            string picpath = "D://05513a251-11.jpg";

            FileStream file = new FileStream(picpath, FileMode.Open);
            byte[] bb = new byte[file.Length];
            file.Read(bb, 0, (int)file.Length);
            file.Close();
            pictureBox2.Image = byteArrayToImage(bb);

            MsMultiPartFormData form = new MsMultiPartFormData();
            form.AddFormField("Filename", Path.GetFileName(picpath));
            form.AddStreamFile("filename", Path.GetFileName(picpath), bb);
            form.AddFormField("Upload", "Submit Query");
            form.PrepareFormData();

            form.GetFormData();
            host = "upload.t.qq.com";
            url = string.Format("http://upload.t.qq.com/asyn/uploadpicCommon.php?call=2&uin={0}&g_tk={1}&rand={2}&_ps1={3}&_ps2=null", uin, weiboGtk, rand.NextDouble(), _ps1);
            ContentType = "multipart/form-data; boundary=" + form.Boundary;

            help = new HttpHelper();
            item = new HttpItem()
            {
                URL = url,
                CookieCollection = cookieCollection,
                ResultCookieType = ResultCookieType.CookieCollection,
                Host = host,
                Accept = "text/*",
                UserAgent = "Shockwave Flash",
                ContentType = ContentType,
                Method = "POST",
                PostDataType = PostDataType.Byte,
                PostdataByte = form.GetFormData().ToArray(),
                Encoding = Encoding.UTF8,
                ProxyIp = "ieproxy"
            };
            item.Header.Add("Pragma", "no-cache");
            item.Header.Add("DNT", "1");
            result = help.GetHtml(item);
            this.BeginInvoke(updateLog, "图片上传结果:" + result.Html);
            return result.Html;
        }

上面是上传的过程,另外用到了:
[C#] 纯文本查看 复制代码
class MsMultiPartFormData
    {
        private List<byte> formData;
        public String Boundary = "----------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2";
        private String fieldName = "Content-Disposition: form-data; name=\"{0}\"";
        private String fileContentType = "Content-Type: {0}";
        private String fileField = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"";
        private Encoding encode = Encoding.GetEncoding("UTF-8");
        public MsMultiPartFormData()
        {
            formData = new List<byte>();
        }
        public void AddFormField(String FieldName, String FieldValue)
        {
            String newFieldName = fieldName;
            newFieldName = string.Format(newFieldName, FieldName);
            formData.AddRange(encode.GetBytes("--" + Boundary + "\r\n"));
            formData.AddRange(encode.GetBytes(newFieldName + "\r\n\r\n"));
            formData.AddRange(encode.GetBytes(FieldValue + "\r\n"));
        }
        public void AddFile(String FieldName, String FileName, byte[] FileContent, String ContentType)
        {
            String newFileField = fileField;
            String newFileContentType = fileContentType;
            newFileField = string.Format(newFileField, FieldName, FileName);
            newFileContentType = string.Format(newFileContentType, ContentType);
            formData.AddRange(encode.GetBytes("--" + Boundary + "\r\n"));
            formData.AddRange(encode.GetBytes(newFileField + "\r\n"));
            formData.AddRange(encode.GetBytes(newFileContentType + "\r\n\r\n"));
            formData.AddRange(FileContent);
            formData.AddRange(encode.GetBytes("\r\n"));
        }
        public void AddStreamFile(String FieldName, String FileName, byte[] FileContent)
        {
            AddFile(FieldName, FileName, FileContent, "application/octet-stream");
        }
        public void PrepareFormData()
        {
            formData.AddRange(encode.GetBytes("--" + Boundary + "--"));
        }
        public List<byte> GetFormData()
        {
            return formData;
        }
    }

Cookie的话,能成功发布文字微博理论上不会有问题,POST提交的参数也对应,难道是在flash里面做了验证吗?


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

抓到了,我发来飞哥帮忙看看:
这个是flash上传成功的抓包
[HTML] 纯文本查看 复制代码
POST [url]http://upload.t.qq.com/asyn/uploadpicCommon.php?call=2&uin=32e43a23301a42e56c67422d10e6515a&g_tk=1084385453&rand=0.1177755375392735&_ps1=ILHi[/url]*AIHIF4lNicNUc9xTL*oA-sxS70Bs4UVX9bFMxI_&_ps2=null HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data; boundary=----------cH2Ef1ae0gL6GI3cH2ei4Ef1KM7Ij5
User-Agent: Shockwave Flash
Host: upload.t.qq.com
Content-Length: 128731
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
Cookie: pgv_pvid=5818015220; ptui_loginuin=1216787788; pt2gguin=o1216787788; RK=6+HTUn0RWa; ptcz=7dce668ac08e22e8a7a9ec9feef1365f848a4b5f1a71defd4d9274d51c2b1189; o_cookie=1216787788; pgv_info=ssid=s6003745550&pgvReferrer=; ptisp=ctc; verifysession=h02pSUVF5qwJ9uuXSduODfxNnaZfaf66jGZOhzDfc4e8ZCrbzII7AAnSvnoCuttcz0BpR5rPhiLqQFpsLpmAtGypg**; uin=o1216787788; skey=@IctcZPVvI; ptwebqq=658f804ab595882aac7a907dae5d46d0db42ccad9e1df6e2b9801b152c5a8a59; wb_regf=%3B0%3B%3Bweb2.qq.com%3B0; wbilang_1216787788=zh_CN; wbilang_10000=zh_CN; myhomeLowQuality=shuyao0101; p_uin=o1216787788; p_skey=ILHi*AIHIF4lNicNUc9xTL*oA-sxS70Bs4UVX9bFMxI_; pt4_token=AwzpFvf06yMMIK*LvtxuQg__; mb_reg_from=8; _as_samba8974=1%2CThu%20Apr%2024%202014

------------cH2Ef1ae0gL6GI3cH2ei4Ef1KM7Ij5
Content-Disposition: form-data; name="Filename"

促销.jpg
------------cH2Ef1ae0gL6GI3cH2ei4Ef1KM7Ij5
Content-Disposition: form-data; name="filename"; filename="促销.jpg"
Content-Type: application/octet-stream

这里是图片
------------cH2Ef1ae0gL6GI3cH2ei4Ef1KM7Ij5
Content-Disposition: form-data; name="Upload"

Submit Query
------------cH2Ef1ae0gL6GI3cH2ei4Ef1KM7Ij5--


这个是C#的模拟发包:
[HTML] 纯文本查看 复制代码
POST [url]http://upload.t.qq.com/asyn/uploadpicCommon.php?call=2&uin=6080e9c85ef16e06d579570bdf367ad7&g_tk=1006495013&rand=0.972169077476565&_ps1=[/url]*XvDvIifBhN51qoYth0HfzjxU7tQVVtIaKJR6FGrfdM_&_ps2=null HTTP/1.1
Pragma: no-cache
DNT: 1
Accept: text/*
Content-Type: multipart/form-data; boundary=----------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2
User-Agent: Shockwave Flash
Host: upload.t.qq.com
Cookie: p_uin=o1216787788; p_skey=lRpz6gjpGWhJfyN4kV7S9vI9Zsa2ECFXNuvvabgHZQc_; pt4_token=IqZ1Mq1vz0C2fW15l6SxDg__; wb_regf=%3B0%3B%3Bweb2.qq.com%3B0; mb_reg_from=8; wbilang_1216787788=zh_CN; wbilang_10000=zh_CN; myhomeLowQuality=shuyao0101; ptisp=ctc; uin_cookie=150935477; euin_cookie=E81EECDFCF0123B8E9115CCE4ED2632B8F33532D1C15F739; ac=1; pt2gguin=o1216787788; ptcz=101076e41346d1bbca42e3e77de123d2496bd9386a8d93a300a5e36d05c94673; pgv_pvid=2870891969; pgv_info=pgvReferrer=&ssid=s1344586586; uin=o1216787788; skey=@IctcZPVvI; RK=mkOKAc0QVf; ptwebqq=62ec521b63301e7edca2b22c9429d339cb8241c50f58cfcff714e32e2ad3bfc7
Content-Length: 128731
Expect: 100-continue
Connection: Keep-Alive

------------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2
Content-Disposition: form-data; name="Filename"

促销.jpg
------------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2
Content-Disposition: form-data; name="filename"; filename="促销.jpg"
Content-Type: application/octet-stream

这里是图片
------------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2
Content-Disposition: form-data; name="Upload"

Submit Query
------------cH2cH2gL6GI3ae0Ef1ae0ae0ae0cH2--
发表于 2014-4-24 10:43:43 | 显示全部楼层
这样肯定不行吧,得把图片转成字节上传,我估计这个你必须得注入Falsh了
 楼主| 发表于 2014-4-24 10:45:53 | 显示全部楼层
站长苏飞 发表于 2014-4-24 10:43
这样肯定不行吧,得把图片转成字节上传,我估计这个你必须得注入Falsh了

图片已经转成字节了,我去看看要怎么注入flash,谢谢飞哥
发表于 2014-4-24 10:50:41 | 显示全部楼层
.順唭_自嘫ɑ 发表于 2014-4-24 10:45
图片已经转成字节了,我去看看要怎么注入flash,谢谢飞哥

恩好的,百度一下,应该有教程
发表于 2014-4-24 20:28:28 | 显示全部楼层
我今天也在折腾这个腾讯上传头像功能,总提示参数错误,楼主有没有解决?求指教
 楼主| 发表于 2014-4-25 10:18:24 | 显示全部楼层
豪侠 发表于 2014-4-24 20:28
我今天也在折腾这个腾讯上传头像功能,总提示参数错误,楼主有没有解决?求指教

解决了,确实是参数的问题,Cookie取值的时候注意下,腾讯有很多Cookie名是重复的,后面的Cookie会覆盖前面的值
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-11-14 14:36

© 2014-2021

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