//获取章节内容 public async static Task <string> GetChapterContent(string bookid, string chapterNum) { string contentText; int num = int.Parse(chapterNum); try { ChapterObject myChapter = await Chapter.GetChapter(bookid); string link = myChapter.mixToc.chapters[num - 1].link; link = link.Replace("/", "%2F"); link = link.Replace("?", "%3F"); ChapterDetailObject myChapterContent = await ChapterDetail.GetChapterDetail(link); contentText = myChapter.mixToc.chapters[num - 1].title + "\n" + myChapterContent.chapter.body; } catch (Exception e) { contentText = "Can not get the content!"; } return(contentText); }
public async static Task <ChapterDetailObject> GetChapterDetail(string link) { ChapterDetailObject data = null; try { var http = new HttpClient(); string url = "http://chapter2.zhuishushenqi.com/chapter/" + link; //string url = "http://chapter2.zhuishushenqi.com/chapter/http:%2F%2Fbook.my716.com%2FgetBooks.aspx%3Fmethod=content&bookId=633074&chapterFile=U_753547_201607012243065574_6770_1.txt"; var response = await http.GetAsync(url); var result = await response.Content.ReadAsStringAsync(); var serializer = new DataContractJsonSerializer(typeof(ChapterDetailObject)); var ms = new MemoryStream(Encoding.UTF8.GetBytes(result)); data = (ChapterDetailObject)serializer.ReadObject(ms); } catch (Exception e) { } return(data); }