Please Help: Posting and redirecting to another form.
- From: "Elton Wang" <anonymous@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Mar 2005 12:05:07 -0800
Hi Denise,
I suppose the key point is to put Response content from
php page (HttpWebResponse) into Response of your page
(this.Response)
You can try following code
//>>>>... how to do I send the user to the page that
follows...?
// Get stream of php page Response
System.IO.BinaryReader phpStream = new BinaryReader
(response.GetResponseStream());
// prepare an byte array for php page content
byte[] phpBytes = new bytes[phpStream.Length];
// get the content
phpStream.Read(phpBytes, 0, phpStream.Length);
phpStream.Close();
// clear current page
this.Response.Clear();
// write php page content to current page
this.Response.BinaryWrite(phpBytes);
// Sends all currently buffered output to the client,
stops execution of the page
this.Response.End();
HTH
Elton Wang
elton_wang@xxxxxxxxxxx
>-----Original Message-----
>I have posted a similar message in 2 other forums but got
no response. I
>have spent more hours than I can count researching this.
Can anyone provide
>some insight...?
>
>Our ASP.Net application needs to transparently log a user
on to a separate
>secure web site (PHP - not controlled by us). We want
to save the user the
>step of typing in his username and password and having to
press submit.
>
>I could accomplish this by using the <form
action="myform.php"
>method="post"> but I would have to store the password in
a hidden field that
>could be easily viewed.
>
>I thought I was on the right track with the below code...
but I cannot
>figure out how to actually redirect the user to the page
that appears after
>login. (Response.redirect only shows the login page
again, even though I
>just posted the login values.)
>
>HttpWebRequest request = (HttpWebRequest)
>WebRequest.Create("https://myServer/myPage.php");
>request.Method = "POST";
>request.ContentType = "application/x-www-form-urlencoded";
>request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1)";
>request.KeepAlive = true;
>request.AllowAutoRedirect = true;
>request.ContentType ="application/x-www-form-urlencoded";
>
>string body
= "logOnUserName=mek&userPwd=mypass&Submit=submit";
>byte[] bytes = Encoding.ASCII.GetBytes(body);
>request.ContentLength = bytes.Length;
>
>StreamWriter stOut = new StreamWriter
(request.GetRequestStream(),
>System.Text.Encoding.ASCII);
>stOut.Write(body);
>stOut.Close();
>HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
>>>>>... how to do I send the user to the page that
follows...?
>
>I have also tried code presented on this forum (below),
but this only brings
>the information into my page, it does not post the
username and password and
>redirect:
>
>private void DoPost()
>{
>String uriString ="https://myServer/myPage.php?";
>System.Net.WebClient myWebClient = new
System.Net.WebClient();
>System.Collections.Specialized.NameValueCollection
>System.Collections.Specialized.NameValueCollection
myNameValueCollection =
>new System.Collections.Specialized.NameValueCollection();
>
>myNameValueCollection.Add("logOnUserName", "me");
>myNameValueCollection.Add("userPwd", "mypass");
>myNameValueCollection.Add("OrganizationId", "1234");
>myNameValueCollection.Add("Submit", "");
>
>myWebClient.UploadValues (uriString, "POST",
myNameValueCollection)
>Byte[] responseArray = myWebClient.UploadValues
(uriString, "POST",
>myNameValueCollection);
>
>Label1.Text = "Response received was : " +
>System.Text.Encoding.ASCII.GetString(responseArray);
>}
>
>Any suggestions would be greatly appreciated!
>.
>
.
- Follow-Ups:
- Prev by Date: Re: response.write question
- Next by Date: .NET Calendar - Triggering Events
- Previous by thread: Re: response.write question
- Next by thread: RE: Please Help: Posting and redirecting to another form.
- Index(es):
Relevant Pages
|