网页表格:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtBxEmail" runat="server"></asp:TextBox>
<asp:TextBox ID="txtBxPassword" runat="server"></asp:TextBox>
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
<br /><br />
<asp:TextBox ID="txtBxLink" runat="server" Text="http://example.com/elements/13579642/"></asp:TextBox>
<asp:Button ID="btnDisplay" runat="server" Text="Display" OnClick="btnDisplay_Click" />
<br /><br />
<asp:TextBox ID="txtBxSource" runat="server" TextMode="MultiLine" Width="600" Height="600"></asp:TextBox>
</div>
</form>
后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
}
CookieContainer loginCookie;
public void btnLogin_Click(object sender, EventArgs e)
{
string postData = "type=0&user=" + txtBxEmail.Text + "&password=" + txtBxPassword.Text + "&remember=0";
CookieContainer tempCookies = new CookieContainer();
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteData = encoding.GetBytes(postData);
HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create("http://example.com/ajax/login.ajax.php");
postReq.Method = "POST";
postReq.KeepAlive = true;
postReq.CookieContainer = tempCookies;
postReq.ContentType = "application/x-www-form-urlencoded";
postReq.Referer = "http://example.com/ajax/login.ajax.php";
postReq.UserAgent = "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.61";
postReq.ContentLength = byteData.Length;
Stream postreqstream = postReq.GetRequestStream();
postreqstream.Write(byteData, 0, byteData.Length);
postreqstream.Close();
HttpWebResponse postresponse = null;
postresponse = (HttpWebResponse)postReq.GetResponse();
tempCookies.Add(postresponse.Cookies);
loginCookie = tempCookies;
StreamReader postreqreader = new StreamReader(postresponse.GetResponseStream());
}
public void btnDisplay_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(txtBxLink.Text);
request.CookieContainer = loginCookie;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string linkSourceCode = reader.ReadToEnd();
txtBxSource.Text = linkSourceCode;
}
您必须登录才能查看http://example.com/elements/13579642/子页面。单击“显示”按钮时,它应该填充txtBxSource
元素源代码,但事实并非如此。相反,它显示了http://example.com/home/源代码。如果我在一切正常的情况下移动整个代码public void btnLogin_Click
,否则它不会。
我的问题的解决方案是什么?
问题:一旦我把整个东西放在一个网站/网络主机上并且有人(通过这个网页)在http://example.com/ 网站上登录并使用这个迷你应用程序,http: //example.com/网站会收到自己的IP还是webhost的IP?