62,047
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
string url = "http://localhost:2420/Default.aspx";
string result = GetResultByUrl(url);
string[] resList=result.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
string userID = resList[0];
string userPwd = resList[1];
}
public string GetResultByUrl(string sURL)
{
WebRequest wrGETURL = null;
Stream objStream = null;
StreamReader objReader = null;
string sLine = null;
try
{
wrGETURL = WebRequest.Create(sURL);
WebProxy myProxy = new WebProxy("myproxy", 80);
myProxy.BypassProxyOnLocal = true;
wrGETURL.Proxy = WebProxy.GetDefaultProxy();
objStream = wrGETURL.GetResponse().GetResponseStream();
objReader = new StreamReader(objStream);
sLine = objReader.ReadToEnd();
}
catch
{
sLine = "wrong";
}
finally
{
if (objReader != null)
{
objReader.Close();
}
if (objStream != null)
{
objStream.Close();
}
if (wrGETURL.GetResponse() != null)
{
wrGETURL.GetResponse().Close();
}
if (wrGETURL != null)
{
wrGETURL.Abort();
}
}
return sLine;
}
在页面中:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("UserID,UserPwd");
Response.End();
}
}