G
Guest
Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!
If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!
my command button
---------------------------
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedomain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&loginId=apientry&password=highview&rememberMe=off","");
ret=htp.httpit("http://my.screenname.aol.com/_cqr/l...%26&isSiteStateEncoded=true&lang=en&locale=us","","");
my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;
namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;
public http()
{
//
// TODO: Add constructor logic here
//
}
public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}
if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}
HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}
class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!
If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!
my command button
---------------------------
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedomain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&loginId=apientry&password=highview&rememberMe=off","");
ret=htp.httpit("http://my.screenname.aol.com/_cqr/l...%26&isSiteStateEncoded=true&lang=en&locale=us","","");
my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;
namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;
public http()
{
//
// TODO: Add constructor logic here
//
}
public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}
if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}
HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}
class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}