473,809 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Post via HttpWebRequest

Hello,

I am trying to automatically login to websites after I have used SSO to get
the credentials. For my test, I am working with my Yahoo account. The code
that I am using is code that many have said works fine. I have done some
tweaking to fit my specific needs. The Problem is when I post to the My
Yahoo login page, the apparently the user name and password are being passed
because my user name is accepted, but I am told that there is an INVALID
PASSWORD. I know the password is correct because I use the account all the
time. Has anyone had this problem? Can anyone help me? Thank you in
advance.

Tony

Here is the code I am using:

void Page_Load(objec t sender, EventArgs e) {

string appURL = "http://login.yahoo.com/config/login";
string strPostData = String.Format(" login={0}&passw ord={1}",
"myloginnam e", "mypassword ");

// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Crea te(appURL) as
HttpWebRequest;
wrWebRequest.Me thod = "POST";
wrWebRequest.Co ntentLength = strPostData.Len gth;
wrWebRequest.Co ntentType = "applicatio n/x-www-form-urlencoded";
wrWebRequest.Co okieContainer = new CookieContainer ();

// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wr WebRequest.GetR equestStream()) ;
swRequestWriter .Write(strPostD ata);
swRequestWriter .Close();

// Get the response.
HttpWebResponse hwrWebResponse =
(HttpWebRespons e)wrWebRequest. GetResponse();

// Have some cookies.
CookieCollectio n ccCookies = hwrWebResponse. Cookies;

// Read the response
StreamReader srResponseReade r = new
StreamReader(hw rWebResponse.Ge tResponseStream ());
string strResponseData = srResponseReade r.ReadToEnd();
srResponseReade r.Close();

// Display the response.
Response.Write( strResponseData );
}
Nov 23 '05 #1
3 31718
Never mind. I figured it out.

Tony

"Tony Hunter" <to*********@mi si.com> wrote in message
news:#V******** *****@TK2MSFTNG P10.phx.gbl...
Hello,

I am trying to automatically login to websites after I have used SSO to get the credentials. For my test, I am working with my Yahoo account. The code that I am using is code that many have said works fine. I have done some
tweaking to fit my specific needs. The Problem is when I post to the My
Yahoo login page, the apparently the user name and password are being passed because my user name is accepted, but I am told that there is an INVALID
PASSWORD. I know the password is correct because I use the account all the time. Has anyone had this problem? Can anyone help me? Thank you in
advance.

Tony

Here is the code I am using:

void Page_Load(objec t sender, EventArgs e) {

string appURL = "http://login.yahoo.com/config/login";
string strPostData = String.Format(" login={0}&passw ord={1}",
"myloginnam e", "mypassword ");

// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Crea te(appURL) as
HttpWebRequest;
wrWebRequest.Me thod = "POST";
wrWebRequest.Co ntentLength = strPostData.Len gth;
wrWebRequest.Co ntentType = "applicatio n/x-www-form-urlencoded";
wrWebRequest.Co okieContainer = new CookieContainer ();

// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wr WebRequest.GetR equestStream()) ;
swRequestWriter .Write(strPostD ata);
swRequestWriter .Close();

// Get the response.
HttpWebResponse hwrWebResponse =
(HttpWebRespons e)wrWebRequest. GetResponse();

// Have some cookies.
CookieCollectio n ccCookies = hwrWebResponse. Cookies;

// Read the response
StreamReader srResponseReade r = new
StreamReader(hw rWebResponse.Ge tResponseStream ());
string strResponseData = srResponseReade r.ReadToEnd();
srResponseReade r.Close();

// Display the response.
Response.Write( strResponseData );
}

Nov 23 '05 #2
Tony, so tell us.... What did it take to get it to work?

Alex

"Tony Hunter" wrote:
Never mind. I figured it out.

Tony

"Tony Hunter" <to*********@mi si.com> wrote in message
news:#V******** *****@TK2MSFTNG P10.phx.gbl...
Hello,

I am trying to automatically login to websites after I have used SSO to

get
the credentials. For my test, I am working with my Yahoo account. The

code
that I am using is code that many have said works fine. I have done some
tweaking to fit my specific needs. The Problem is when I post to the My
Yahoo login page, the apparently the user name and password are being

passed
because my user name is accepted, but I am told that there is an INVALID
PASSWORD. I know the password is correct because I use the account all

the
time. Has anyone had this problem? Can anyone help me? Thank you in
advance.

Tony

Here is the code I am using:

void Page_Load(objec t sender, EventArgs e) {

string appURL = "http://login.yahoo.com/config/login";
string strPostData = String.Format(" login={0}&passw ord={1}",
"myloginnam e", "mypassword ");

// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Crea te(appURL) as
HttpWebRequest;
wrWebRequest.Me thod = "POST";
wrWebRequest.Co ntentLength = strPostData.Len gth;
wrWebRequest.Co ntentType = "applicatio n/x-www-form-urlencoded";
wrWebRequest.Co okieContainer = new CookieContainer ();

// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wr WebRequest.GetR equestStream()) ;
swRequestWriter .Write(strPostD ata);
swRequestWriter .Close();

// Get the response.
HttpWebResponse hwrWebResponse =
(HttpWebRespons e)wrWebRequest. GetResponse();

// Have some cookies.
CookieCollectio n ccCookies = hwrWebResponse. Cookies;

// Read the response
StreamReader srResponseReade r = new
StreamReader(hw rWebResponse.Ge tResponseStream ());
string strResponseData = srResponseReade r.ReadToEnd();
srResponseReade r.Close();

// Display the response.
Response.Write( strResponseData );
}


Nov 23 '05 #3
Sougata
1 New Member
Here is the solution...try it

replace the part of your code by (not 'password'...wi ll be 'passwd') -

string strPostData = String.Format(" login={0}&passw d={1}",
"myloginnam e", "mypassword ");

Enjoy !!!

Hello,

I am trying to automatically login to websites after I have used SSO to get
the credentials. For my test, I am working with my Yahoo account. The code
that I am using is code that many have said works fine. I have done some
tweaking to fit my specific needs. The Problem is when I post to the My
Yahoo login page, the apparently the user name and password are being passed
because my user name is accepted, but I am told that there is an INVALID
PASSWORD. I know the password is correct because I use the account all the
time. Has anyone had this problem? Can anyone help me? Thank you in
advance.

Tony

Here is the code I am using:

void Page_Load(objec t sender, EventArgs e) {

string appURL = "http://login.yahoo.com/config/login";
string strPostData = String.Format(" login={0}&passw ord={1}",
"myloginnam e", "mypassword ");

// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Crea te(appURL) as
HttpWebRequest;
wrWebRequest.Me thod = "POST";
wrWebRequest.Co ntentLength = strPostData.Len gth;
wrWebRequest.Co ntentType = "applicatio n/x-www-form-urlencoded";
wrWebRequest.Co okieContainer = new CookieContainer ();

// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wr WebRequest.GetR equestStream()) ;
swRequestWriter .Write(strPostD ata);
swRequestWriter .Close();

// Get the response.
HttpWebResponse hwrWebResponse =
(HttpWebRespons e)wrWebRequest. GetResponse();

// Have some cookies.
CookieCollectio n ccCookies = hwrWebResponse. Cookies;

// Read the response
StreamReader srResponseReade r = new
StreamReader(hw rWebResponse.Ge tResponseStream ());
string strResponseData = srResponseReade r.ReadToEnd();
srResponseReade r.Close();

// Display the response.
Response.Write( strResponseData );
}
May 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4613
by: james | last post by:
How can I have a php script send data to a URL as form post data from within the script without creating an actual form in a web page. I am working with an affiliate program (from Affiliateshop) and the instructions are 'have your script send a form post with the name of the form fields "AID" and "BID" and their values to the following URL string...' Thanks james
1
1314
by: Jeremy Phillips | last post by:
I am trying to build a web form that uses the "POST" method (too much data for GET) to send data to a second form, then displays the response of that form post. The second web form requires standard authentication. I have a solution implemented in which the following occurs: 1) My website posts form data to a backend cgi script. 2) The script authenticates and sends data to the second form. 3) The script downloads and prints the...
2
3741
by: | last post by:
Hi everyone, I'm using VS.NET, Framework 1.1, Windows 2000 Server, IIS 5, all the latest patches are installed. Im having this wierd random problem, that I cannot reproduce but it happens quite often: - my Request.Form collection is truncated in some posts (again I dont know why or how to reproduce it).
4
7086
by: Al Cadalzo | last post by:
I'm trying to simulate a form post (i.e. Method="POST"). The FORM POST I'm trying to simulate is similar to this: <FORM NAME=SearchForm METHOD=POST ACTION=Search> <SELECT name="criteriaA" > <OPTION VALUE=1>AAAAAAAAAAA</OPTION> <OPTION VALUE=2>BBBBBBBBBBBB</OPTION> </SELECT> ....
4
1537
by: Ron Vecchi | last post by:
I know this has messiness written all over it but I have a question about using HttpWebRequest/Response to essentially spider a website and post information to the forms. The (very) basic goal is to progmattically access a login account by posting the username and password and then maintaining the session so that the program can continue to access web pages that require a valid login sesssion. The big if for me is maintaining the...
1
1917
by: guoqi zheng | last post by:
I know in webclient class, there is a possibility to post form data to a remote url, but how can I not only just post, I need to redirect user to that page as well. So what I want is just like a user click submit button of a regular html form and this form post to a remote URL, user will go there as well... How can I do this? any example?? regards,
1
6935
by: John Braham | last post by:
I have a slight wall headbutter which I'm hoping someone will have an idea for (I'd be very grateful!). Basically I'm trying to make a form post to an asp page programatically from within VB.NET 2005, the only data posted is one hidden field XMLDOC, which contains an xml file which the receiving page will respond to... I know, it's not a great way of doing this... I know I should be using a web service, but basically this is the way I...
10
2445
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a file input element in it. Ultimately what I want to do is get a file off client machine (that they specify) and send it to the server using a standard post request. This is exactly the same as a form post with an file input element, but I don't...
0
4116
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with "The remote server returned an error: (500) Internal Server Error". Obviously, this means that I have not posted all the parameters as the servlet requested. But I just can't seem to find out what went wrong with my code. Hope someone can enlighten me,...
0
4698
by: magix | last post by:
Hi, I launched a modal popup window with code like: <script language="javascript"> function modalWin() { if (window.showModalDialog) { window.showModalDialog("MyPage1.asp","MyPopup", "dialogWidth:500px;dialogHeight:400px"); } else { window.open('MyPage1.asp,'MyPopup',
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.