日期:2014-05-17 浏览次数:20774 次
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;