2019年5月28日之前的兩三個月時間,使用cnblogs原來的接口時,提示圖片沒法上傳,空間不足,實在沒辦法了,本身實現了博客代理,發現上傳圖片時返回了503錯誤,只好先把圖片傳到其它服務器,再發布 web
http://www.cnblogs.com/qinqoushui/services/metaweblog.aspx 服務器
新接口 ui
https://rpc.cnblogs.com/metaweblog/QinQouShui url
而後,cnblogs忽然換了接口,圖片上傳正常了,一切都白費力氣 spa
public Stream newMediaObjectResponse(string blogid, string username, string password, FileData file) 代理
{ code
//可行,偷樑換柱,先實現圖片上傳 xml
if (string.IsNullOrEmpty(imageUrl)) blog
{ 接口
mw.Credentials = new NetworkCredential(username, password);
var x = mw.newMediaObject(blogid, username, password, file);
return mw.newMediaObjectResponse(blogid, username, password, file).GetResponseStream();
}
else
{
string md5 = Q.Helper.HashHelper.MD5(file.bits);
string path = System.IO.Path.Combine(AppContext.BaseDirectory, "images");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileName = md5 + "." + file.type.Split('/')[1];
if (!File.Exists(Path.Combine(path, fileName)))
File.WriteAllBytes(Path.Combine(path, fileName), file.bits);
XmlRpcResponse xmlRpcResp = new XmlRpcResponse(new UrlData() { url = $"{imageUrl}{fileName}" });
XmlRpcSerializer serializer = new XmlRpcSerializer();
Stream responseStream = new MemoryStream();
serializer.SerializeResponse(responseStream, xmlRpcResp);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
}
@@#
記念下