更新了UWP应用桌面记事本,新增一个功能.客户端提交文章到服务器.事实上有不少博客服务提供商都支持Post提交数据.应用的Post过程参数是软件内输入的.如果具有一定开发能力的开发者,可以使用本编辑器,进行文章提交.下面把UWP的Post提交代码贴出来,可以让接入者更多了解程序的工作原理.
public class PostBlog { public static string Post(string blogHost, string username, string password, string title, string keywords, string content, string accesstoken, string secretkey) { HttpClient client = new HttpClient(); List<KeyValuePair<String, String>> paraList = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("username", username), new KeyValuePair<string, string>("password", password), new KeyValuePair<string, string>("title", title), new KeyValuePair<string, string>("keywords", keywords), new KeyValuePair<string, string>("content", content), new KeyValuePair<string, string>("accesstoken", accesstoken), new KeyValuePair<string, string>("secretkey", secretkey), }; HttpResponseMessage response = client.PostAsync(blogHost, new FormUrlEncodedContent(paraList)).Result; String result = response.Content.ReadAsStringAsync().Result; return result; } }
UWP桌面记事本使用微软word系统的rtf(富文本)插件,接入了rtf转html工具.编辑器编辑的结果是rtf,转换成html提交到服务器.因此上面的方法中.参数content是html文本.并且只选取了body的innerhtml部分.也就是说只要将content加入任意div中就可以在web页面中显示内容了.如果更改过字体样式,p段落的style信息继续保留,html文本没有css关联,因此如果没有进行任何样式变更,显示效果取决于网页的CSS style。
因为都是微软的做出来的东西,直接从VS或者word复制文本,样式可以得到部分保留,比如代码文本复制过来,代码仍然是高亮显示的,理论上word中的简单公式都可以得到部分保留,但不能保证html完全无差别显示,毕竟word自带的转html功能都做不到,已经是可以接受的程度。
rtf转html的过程,如果rtf文件内嵌了图片的话,转换过程会慢一些,因为转换为html的时候图片同样是需要内嵌data到img标签的src里面的,同时转换成的html文件会相比使用地址的臃肿.