public string GetHttpResponse(string url, int timeout = 60000)
    {
        
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.ContentType = "text/html;charset=UTF-8";
        request.UserAgent = null;
        request.Timeout = timeout;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream myResponseStream = response.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
        string retString = myStreamReader.ReadToEnd();
        //通过JavaScriptSerializer获取json的单个值
        JavaScriptSerializer Jss = new JavaScriptSerializer();
        Dictionary<string, object> DicText = (Dictionary<string, object>)Jss.DeserializeObject(retString);
        string city = DicText["city"].ToString();
        string tip = DicText["air_tips"].ToString();
        this.tianqi.Text = city + tip;
        myStreamReader.Close();
        myResponseStream.Close();
        return retString;
        
    }
    protected void Page_Load(object sender, EventArgs e)
    {
       
         
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string tqid = this.tqid.Text;
        string miyao = "u03CST0U";
        string url = "https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=" + tqid + "&appsecret=" + miyao;
        int timeout = 60000;
        GetHttpResponse(url, timeout);
    }
© 版权声明
THE END
    











![WordPress博客系统侧边栏添加恋爱天数代码小工具[WP教程]-狂神云浏览专注活动,软件,教程分享!总之就是网络那些事。](https://www.atbkw.cn/wp-content/uploads/2021/09/15488586d633.png)







暂无评论内容