日期:2014-05-17  浏览次数:20753 次

利用公众平台模拟上传图片,老是返回上传文件失败,急...
大家帮帮忙:
最近遇到一个问题一直解决不了,我模拟登录获取cookie后想上传图片,但是老上上传不上去,服务器返回失败.
返回了一段javascript

<script>
document.domain = location.hostname.match(/[^\.]*?\.[^\.]*?$/);
var
url = window.location.href,
type = url.match(/[\?&]type=([^&]*)/),
formId = url.match(/[\?&]formId=([^&]*)/);
type = type[1] || 0;
formId = formId[1];
top.W.upload.err("上传文件失败", type, formId);
</script>

谁能告诉我是那方面出问题了,还是说服务器判断出来了吗?没有一点头绪.

------解决方案--------------------
public static string UploadFile(string fileSrc)
        {
            CookieContainer cookie = LoginInfo.LoginCookie; //模拟登录获得的cookie
            string token = LoginInfo.Token;                 //模拟登录获得的Token

            HttpWebRequest req;
            string url = @"https://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=2&token={0}&t=iframe-uploadfile&lang=zh_CN&formId=file_from_1341151893625";
            url = string.Format(url, token);
            req = (HttpWebRequest)WebRequest.Create(url);
            string filePath = fileSrc;                     //要上传文件本地路径,如D:\\ms.jpg
            byte[] filebytes = File.ReadAllBytes(filePath);
            req.Method = "POST";
            req.Accept = "*/*";
            req.AllowAutoRedirect = true;