C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpWebRequest]

C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpWebRequest]

  1. void Main()
  2. {
  3. string apiUrl = "http://aaa/bbb/ccc?x=11&y=222";
  4. string Msg = "";
  5. HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(apiUrl);
  6. req.Method = "GET";
  7. req.ContentType = "application/json";
  8. req.Timeout = 3000000; //以毫秒為單位
  9. using (HttpWebResponse wr = (HttpWebResponse)req.GetResponse())
  10. {
  11. if (wr.StatusCode == HttpStatusCode.OK)
  12. {
  13. using (Stream stream = wr.GetResponseStream())
  14. using (StreamReader reader = new StreamReader(stream))
  15. {
  16. Msg = reader.ReadToEnd();
  17. }
  18. }
  19. }
  20. RDataSS RData = JsonConvert.DeserializeObject<RDataSS>(Msg);
  21. RData.Dump();
  22. }
  23. // Define other methods and classes here
  24. public class RDataSS
  25. {
  26. public string ReturnCode { get; set; }
  27. public string Message { get; set; }
  28. public string StorageID { get; set; }
  29. }

 

留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 工作排程 DBMS_JOB 筆記

Oracle 例外控制(Exception Control)