usingsystem;
using
system.collections.generic;
using
system.io;
using
system.linq;
using
system.net;
using
system.text;
using
system.web;
namespace
w.bll.wechat";
url = string
.format(url, accesstoken);
//設定提交表單的名稱
string formname = materialtype == "
video
" ? "
description
" : "
media";
byte datas = null
;
#region 組合正文
//換行string crlf = "
\r\n";
//邊界標識
string identification = "
----
" + datetime.now.tostring("
yyyy-mm-dd hh:mm:ss");
try\"");
}//頭部與尾部
string header =sb.tostring();
string foot = crlf + "
--" + identification + "
--" +crlf;
//轉為byte流
byte headerbytes =encoding.utf8.getbytes(header);
byte footbytes =encoding.utf8.getbytes(foot);
list
datalist = new list();
//轉換為btye資料流
stream stream =isfile.inputstream;
byte data = new
byte
[stream.length];
stream.read(data,
0, data.length);
//設定當前流的位置為流的開始
stream.seek(0
, seekorigin.begin);
datalist.addrange(headerbytes);
datalist.addrange(data);
datalist.addrange(footbytes);
//組合完整的流資料
datas = datalist.toarray();
}catch
(exception)
#endregion
return
materialupload(datas, url, identification);
}//////
/// ///
//////
正文邊界
///public
static
string materialupload(byte data, string url, string
identification)
", url));
}request.useragent = "
mozilla/4.0 (compatible; msie 7.0; windows nt 5.2; .net clr 1.1.4322; .net clr 2.0.50727)";
request.contenttype = "
multipart/form-data; boundary=
" +identification;
// request.method = "
post";
request.contentlength =data.length;
stream requeststream =request.getrequeststream();
requeststream.write(data,
0, data.length);
requeststream.close();
try
catch
(exception exception)
string str = string
.empty;
using (streamreader reader = new streamreader(responsestream, encoding.getencoding("
utf-8
")))
responsestream.close();
return
str;}}
}
微信開發之上傳素材
本文目錄 上傳 素材的 上傳其他素材 關鍵的http表單請求 小結參考文件 文中遇到諸如getaccesstoken 等關鍵函式卻沒有找到實現時,可參考前面的這兩篇文章 1 上傳 素材的 首先選乙個簡單的介面來做說明例子,這個上傳素材的介面在所有上傳素材的介面中是引數最簡單的,而且還單獨享用乙個ur...
微信開發之上傳素材
上傳 素材的 上傳其他素材 關鍵的http表單請求 小結參考文件 前言 1 上傳 素材的 首先選乙個簡單的介面來做說明例子,這個上傳素材的介面在所有上傳素材的介面中是引數最簡單的,而且還單獨享用乙個url,作為入門例子再合適不過了。官方文件 新增永久素材 官方給的這個介面,除了需要慣例的access...
微信上傳素材
function curlpost url,param is post 1,timeout 5 顯示輸出結果 1代表 把介面返回的結果當作乙個字串處理 curl setopt curl,curlopt returntransfer,1 設定請求超時時間 curl setopt curl,curlop...