Today, I found a free weather forecast Web Service on the Internet, so I used C #2005 to do a weather forecast program called webservice, which can display weather images.
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Net;
Using System. IO;
Namespace WSWeather
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Private void btn_ OK _Click (object sender, EventArgs e)
{
Try
{
Com. wopos. www. Weather w = new WSWeather.com. wopos. www. Weather ();
String s = w. getWeather (this. cb_city.SelectedItem.ToString (). Trim ());
String [] temp;
Char [] split = {','};
Char [] trim1 = {'fig', '1', '=', '= '};
Char [] trim2 = {'fig', '2', '=', '= '};
Temp = s. Split (split );
This. lb_city.Text = temp [0];
This. lb_date.Text = temp [1];
This. lb_temper.Text = temp [5];
This. lb_weather.Text = temp [4];
This. lb_wind.Text = temp [6];
This. lb_vilet.text = temp [7];
WebRequest request1 = WebRequest. Create (temp [2]. TrimStart (trim1 ));
WebRequest request2 = WebRequest. Create (temp [3]. TrimStart (trim2 ));
Request1.Credentials = CredentialCache. DefaultCredentials;
Request2.Credentials = CredentialCache. DefaultCredentials;
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse ();
HttpWebResponse response2 = (HttpWebResponse) request2.GetResponse ();
Stream imagestream1 = response1.GetResponseStream ();
Stream imagestream2 = response2.GetResponseStream ();
Image im1 = Image. FromStream (imagestream1, true, true );
Image im2 = Image. FromStream (imagestream2, true, true );
This. pb_image1.Image = im1;
This. pb_image2.Image = im2;
}
Catch (Exception oe)
{
// MessageBox. Show ("input city Error or network Error", "Error", MessageBoxButtons. OK, MessageBoxIcon. Error );
MessageBox. Show (oe. Message );
}
}
}
}