一、 转换为 base64
public static string ObtainBase64FromWeb(string domain, string path)
{
string url = "https://" + domain + path;
System.Net.WebRequest webReq = System.Net.WebRequest.Create(url);
System.Net.WebResponse webRes = webReq.GetResponse();
System.IO.Stream webStream = webRes.GetResponseStream();
byte[] buf; // 网络流不支持查找操作,通过 response 长度, 将其转化为 byte[] 进行转换
using (BinaryReader br = new BinaryReader(webStream))
{
int len = (int)(webRes.ContentLength);
buf = br.ReadBytes(len);
br.Close();
}
webStream.Close();
webRes.Close(); string base64_string = Convert.ToBase64String(buf, , buf.Length);
return base64_string;
}