Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The problem that I am facing at the moment is to extract User:Password fromt he following URL :
HTTPS://User:Password@www.myURL.com/default.aspx?address=xyz&phone=234563

Request Method is POST. Implementation of the above example is done as follows:
I have two pages one Creates a REquest object and the other page Gets the Request using Request.Url.toString()

The code for the page sending the request is as follows:
C#
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://User:Password@localhost:2721/TestWebApp/Default.aspx");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string strNewValue = @"&MessageId=123&DestinationAddress=46762050312";
req.ContentLength = strNewValue.Length;
// Write the request
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
HttpWebResponse res = (HttpWebResponse) req.GetResponse();
Stream resst = res.GetResponseStream();
StreamReader sr = new StreamReader(resst);
string response = sr.ReadToEnd();
Response.Write(response);

Page receiving the request is coded as follows:
C#
string    str = Request.Url.ToString();

On receiving the request "str" only contains: http://localhost:2721/TestWebApp/Default.aspx
User: Password is missing .


Please let me know how can I retrieve the USer and password from above URL.
Posted
Updated 11-Oct-10 7:25am
v2
Comments
Sandeep Mewara 11-Oct-10 13:26pm    
Using PRE tags to format code part makes the contect readable. Please use them from next time.

1 solution

Following some concerns with malicious software, the ability to use username and password combinations in the url was disabled by default in IE. As such the browser strips this before posting.

It can be re-enabled, but is not recommended method of transporting the info.

See this Support Article at Microsoft;
http://support.microsoft.com/kb/834489[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900