Utility/Weather.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace Utility
{
public class Weather
{
/// <summary>
/// 获取今天气温,远程捕获
/// </summary>
/// <param name="strUrl"></param>
/// <returns></returns>
public static string GetWeatherToday()
{
string strUrl = System.Configuration.ConfigurationManager.AppSettings["Weather"].Trim();
string WeatherToday = "";
if (UrlExistsUsingSockets(strUrl))
{
WebRequest wreq = WebRequest.Create(strUrl);
WebResponse wresp = (WebResponse)wreq.GetResponse();
Stream s = wresp.GetResponseStream();
StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("utf-8"));
string HTML = sr.ReadToEnd();
int laststr = HTML.LastIndexOf("℃");
if (laststr > 0)
{
string Newhtml = HTML.Substring(0, laststr + 1);
int startstr = Newhtml.LastIndexOf(">");
int mylen = laststr - startstr;
WeatherToday = Newhtml.Substring(startstr + 1, mylen);
}
else
{
WeatherToday = " 天气预报解析不成功!";
}
}
else
{
WeatherToday = " 获取天气预报失败!";
}
return WeatherToday;
}
/// <summary>
/// 方法一、检测远程url是否存在
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private static bool UrlExistsUsingHttpWebRequest(string url)
{
try
{
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
myRequest.Method = "HEAD";
myRequest.Timeout = 100;
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)myRequest.GetResponse();
后面还有 29 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
