IPLocationTool.cs 829 B

123456789101112131415161718192021222324
  1. using Azylee.YeahWeb.HttpUtils;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. namespace Azylee.YeahWeb.BaiDuWebAPI.IPLocationAPI
  9. {
  10. public static class IPLocationTool
  11. {
  12. const string URL = "http://map.baidu.com/?qt=ipLocation";
  13. public static IPLocationModel GetLocation()
  14. {
  15. IPLocationWebModel model = null;
  16. CookieCollection cookie = new CookieCollection();
  17. string rss1 = HttpToolPlus.Get(URL, ref cookie);//第一次请求以获取Cookie
  18. string rss2 = HttpToolPlus.Get(URL, ref cookie);//携带第一次的Cookie获取数据
  19. model = JsonConvert.DeserializeObject<IPLocationWebModel>(rss2);
  20. return model.ToIPLocationModel();
  21. }
  22. }
  23. }