
October 11th, 2012, 03:21 PM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 64
  
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(postBytes, 0, postBytes.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 sender, X509Certificate certification, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
|