C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2012, 02:14 PM
dlopez dlopez is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 64 dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 33 m 11 sec
Reputation Power: 3
HttpWebRequest then redirect

What I have, so far is code that logs into an https website. What I need it to do afterwards is redirect... What should I do?

PHP Code:
 using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace 
TownClass
{
    class 
Program
    
{
        public static 
void Main(string[] args)
        {
            
string username "userName";
            
string password "Password";
            
string url "https://www6.iso.com/auth/global/loginAction.do?req_url=https://www5.iso.com/cmc/app/start.do";
            
string post_data "userId=" username "&userPassword=" password "&req_url=https://www5.iso.com/cmc/app/start.do";
            
            
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
            
            
Uri uri = new Uri(url);
            
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            
request.KeepAlive true;
            
request.ProtocolVersion HttpVersion.Version10;
            
request.Method "POST";
            
request.MaximumAutomaticRedirections 10;
            
request.AllowAutoRedirect true;
            
// turn our request string into a byte stream
            
byte[] postBytes Encoding.ASCII.GetBytes(post_data);
            
            
// specify type
            
request.ContentType "application/x-www-form-urlencoded";
            
request.ContentLength postBytes.Length;
            
Stream requestStream request.GetRequestStream();
            
            
Console.WriteLine(request.Address);
            
            
// now sent it
            
requestStream.Write(postBytes0postBytes.Length);
            
requestStream.Close();
            
            
// grab response and print it out to the console along with the status code
            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            
Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
            
Console.WriteLine(response.StatusCode);
            
            
Console.WriteLine(request.Address);
            
Console.Read();
        }
        
        
// Certificate trap
        
public static bool AcceptAllCertifications(object senderX509Certificate certificationX509Chain chainSslPolicyErrors sslPolicyErrors)
        {
            return 
true;
        }
    }


Reply With Quote
  #2  
Old October 11th, 2012, 03:16 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Redirect who? Where? This is a console app.

Reply With Quote
  #3  
Old October 11th, 2012, 03:21 PM
dlopez dlopez is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 64 dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 33 m 11 sec
Reputation Power: 3
I'm using the console app to access the page. Since this, I've changed it. I'm now attempting to grab the cookie and just use it to gather the information that I need. However, the cookie isn't working, or I have something wrong.

PHP Code:
 using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace 
TownClass
{
    class 
Program
    
{
        private static 
string username "username";
        private static 
string password "password";
        private static 
CookieContainer cookieContainer = new CookieContainer();
        
        public static 
void Main(string[] args)
        {            
            
// Set Cookie
            
setCookie();
            
            
// Return the state webaddresses
            
ReturnStateInfo("https://www5.iso.com/cmc/app/start.do");
        }
        
        public static 
void ReturnStateInfo(string url)
        {
            
ServicePointManager.ServerCertificateValidationCallback 
                new 
RemoteCertificateValidationCallback(AcceptAllCertifications);
            
            
Uri uri = new Uri(url);
            
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            
request.CookieContainer cookieContainer// this must be set
            
request.KeepAlive true;
            
request.ProtocolVersion HttpVersion.Version10;
            
request.Method "POST";
            
request.MaximumAutomaticRedirections 10;
            
request.AllowAutoRedirect true;
            
            
// grab response and print it out to the console along with the status code
            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            
            
// For debugging purposes, show the status codes
            
Console.WriteLine(response.StatusCode);
            
Console.WriteLine(response.Server);
            
Console.WriteLine(response.StatusDescription);
            
            
// Read the response
            
Stream answer response.GetResponseStream();
            
StreamReader _answer = new StreamReader(answer);
            
Console.WriteLine(_answer.ReadToEnd());
            
            
Console.ReadLine();
        }
        
        public static 
void setCookie()
        {
            
string url "https://www6.iso.com/auth/global/loginAction.do";
            
string post_data "userId=" username "&userPassword=" password;
            
            
ServicePointManager.ServerCertificateValidationCallback 
                new 
RemoteCertificateValidationCallback(AcceptAllCertifications);
            
            
Uri uri = new Uri(url);
            
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            
request.KeepAlive true;
            
request.ProtocolVersion HttpVersion.Version10;
            
request.Method "POST";
            
request.MaximumAutomaticRedirections 10;
            
request.AllowAutoRedirect true;
            
            
// turn our request string into a byte stream
            
byte[] postBytes Encoding.ASCII.GetBytes(post_data);
            
            
// specify type
            
request.ContentType "application/x-www-form-urlencoded";
            
request.ContentLength postBytes.Length;
            
Stream requestStream request.GetRequestStream();
            
            
// now sent it
            
requestStream.Write(postBytes0postBytes.Length);
            
requestStream.Close();
            
            
// grab response and print it out to the console along with the status code
            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            
            
// set the cookie for reuse
            
request.CookieContainer cookieContainer;
        }
        
        
        
        
        
// Certificate trap
        
public static bool AcceptAllCertifications(object senderX509Certificate certificationX509Chain chainSslPolicyErrors sslPolicyErrors)
        {
            return 
true;
        } 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > HttpWebRequest then redirect

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap