本文整理汇总了C#中System.Utils.HttpUpload方法的典型用法代码示例。如果您正苦于以下问题:C# Utils.HttpUpload方法的具体用法?C# Utils.HttpUpload怎么用?C# Utils.HttpUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Utils
的用法示例。
在下文中一共展示了Utils.HttpUpload方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add
public void add(JabinfoContext context)
{
Weixin weixin = new Weixin ();
Utils util = new Utils ();
if (!context.IsPost) {
return;
}
context.Post ["uploadId"] = Jabinfo.Help.Basic.JabId;
string type = context.Post ["type"];
string fileName = context.Files ["afile"].FileName;
string model=fileName.Substring(fileName.LastIndexOf('.') + 1);
Jabinfo.Help.Upload.Save (context.Post ["uploadId"], context.Files["afile"],model);
string file = Jabinfo.Help.Upload.PysPath (context.Post ["uploadId"],model);
string url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+weixin.GetAccessToken();
url = url + "&type=" + type;
string json = util.HttpUpload (url, file);
context.Post ["mediaId"] = weixin.GetJsonValue (json,"media_id");
context.Post ["createdAt"] = weixin.GetJsonValue(json,"created_at");
if (!string.IsNullOrEmpty (weixin.GetJsonValue (json, "errcode"))) {
context.Jump ("/article/upload/home","无效媒体类型,请重新上传");
return;
}
UploadMapper.I.Insert(context.Post);
context.Refresh ();
}
示例2: upload
/// <summary>
/// 上传媒体文件
/// </summary>
/// <param name="context">Context.</param>
/// <param name="articles">Articles.</param>
public void upload(JabinfoContext context,string articles)
{
if (!context.IsPost) {
context.Variable ["articles"] = articles;
return;
}
Weixin wx = new Weixin ();
Utils util = new Utils ();
string[] article =context.Post["articles"].Split (',');
StringBuilder str = new StringBuilder ("{ \r\n");
StringBuilder con = new StringBuilder ();
str.Append (" \"articles\": [ \r\n");
for (int i = 0; i < article.Length - 1; i++) {
ArticleVO ar = ArticleMapper.I.Create (article [i]);
ArticleDetailVO d = ArticleDetailMapper.I.Create (article [i]);
con.Append("{ \r\n");
Regex reg = new Regex(@"(?i)</?a\b[^>]*>"); //去掉字符串的<a>标签
Regex reg1=new Regex(@"<img[^>]*?/>"); //去掉img标签
Regex reg2=new Regex(@"style=""[^""]*"""); //去掉style标签
string result = reg.Replace(d.content, "");
result = reg1.Replace (result, "");
result = reg2.Replace (result, "");
string file = Jabinfo.Help.Upload.PysPath (ar.articleId,"jpg");
string url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+wx.GetAccessToken();
url = url + "&type=image";
string json = util.HttpUpload (url, file);
con.Append (string.Format(" \"thumb_media_id\":\"{0}\", \r\n",wx.GetJsonValue (json,"media_id")));
con.Append("\"author\":\"" + ar.author.ToString() + "\",");
con.Append("\"title\":\"" + ar.title.ToString() + "\",");
con.Append(string.Format(" \"content_source_url\":\"{0}\", \r\n","http://wx.zento.me/article/home/detail/"+ ar.articleId));
con.Append("\"content\":\"" + Jabinfo.Help.Formate.ClearSpace(result) + "\",");
con.Append("\"digest\":\"" + Jabinfo.Help.Formate.ClearSpace(ar.summary) + "\",");
con.Append (" \"show_cover_pic\":\"0\" \r\n");
con.Append (" },");
}
string mian = con.ToString ();
string text = mian.Substring (0, mian.Length - 1);
str.Append (text);
str.Append (" ] \r\n");
str.Append ("} \r\n");
wx.UpNews (str.ToString (),context.Post["title"]);
context.Refresh ();
}