Click here to Skip to main content
15,921,542 members
Home / Discussions / C#
   

C#

 
GeneralRe: Registry problem..! Pin
QzRz29-Oct-04 11:46
QzRz29-Oct-04 11:46 
GeneralRe: Registry problem..! Pin
Dave Kreskowiak29-Oct-04 18:49
mveDave Kreskowiak29-Oct-04 18:49 
GeneralRe: Registry problem..! Pin
QzRz29-Oct-04 23:14
QzRz29-Oct-04 23:14 
Generalresponding to javascript in html Pin
JeromeKJerome28-Oct-04 8:02
JeromeKJerome28-Oct-04 8:02 
GeneralRe: responding to javascript in html Pin
Heath Stewart28-Oct-04 15:48
protectorHeath Stewart28-Oct-04 15:48 
GeneralRe: responding to javascript in html Pin
JeromeKJerome28-Oct-04 16:17
JeromeKJerome28-Oct-04 16:17 
GeneralRe: responding to javascript in html Pin
Heath Stewart29-Oct-04 5:28
protectorHeath Stewart29-Oct-04 5:28 
GeneralRe: responding to javascript in html Pin
JeromeKJerome29-Oct-04 8:08
JeromeKJerome29-Oct-04 8:08 
Below find the code for my web retrieves, adapted from Johnvey's Gmail Agent (Code Project).

What is returned after calling this the first time is simply the html of the first page and with it a cookie. On the second retrieve, I simply make a retrieve identical to the first one, but this time there is a cookie to send that I got from the first response. The result of the second call is also simply an html page. No javascript either time. (Perhaps this double retrieve is unneccesary, it works and I've never tried retrieving it only once. Have to put that on the todo list...)

I should also mention that this first/second page retrieve involves one redirect. I think the redirect is used to pass the cookie and possibly the javascript as well, so maybe the javascript is coming in as a response to the page I am not seeing because it is redirected.


private string MakeNewWebRequest(Uri location, string method, string referrer, string postData, bool allowAutoRedirect)
{

// prepare HTTP request
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(location);
webRequest.CookieContainer = new CookieContainer();
if (cookieJar!=null)
{
webRequest.CookieContainer.Add(webRequest.RequestUri, this.cookieJar.GetCookies(webRequest.RequestUri));

}
else
{
System.Windows.Forms.MessageBox.Show("No CookieJar!", "Debug");
}


// if POSTing, add request page and modify the headers
byte[] encodedPostData = new byte[0];
if(method == "POST")
{
ASCIIEncoding encoding = new ASCIIEncoding();
encodedPostData = encoding.GetBytes(postData);
webRequest.Method = "POST";
webRequest.ContentType="application/x-www-form-urlencoded";
webRequest.ContentLength = encodedPostData.Length;
}
else
{
webRequest.Method = "GET";
webRequest.ContentType = "text/html";
}
webRequest.Timeout=295000; // 295 seconds (4 min 55 sec) supports long downloads
webRequest.Headers["Accept-Language"] = "en-us";
webRequest.Headers["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
webRequest.ProtocolVersion = HttpVersion.Version11;
webRequest.AllowAutoRedirect = allowAutoRedirect;
webRequest.KeepAlive = true;
webRequest.Referer = referrer;
webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040626 Firefox/0.8";
webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* ";
//sample cookie "Cookie:WEBTRENDS_ID=68.255.78.35-1098489905.786792::588AC2E5087CF3F2AD7B775FB2116AB2; ForeseeLoyalty_MID_dh4QBcM8h8=55"
//note: cookie may also be JSESSIONID
//Attempt to send request stream to server if POSTing
if(method == "POST")
{
Stream requestStream = null;

try
{

requestStream = webRequest.GetRequestStream();
requestStream.Write(encodedPostData, 0, encodedPostData.Length);

}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);

}
finally
{
if(requestStream != null)
{
requestStream.Close();
}
}
}

// Attempt to get response from server
HttpWebResponse webResponse = null;
string output = "";
try
{
string
headers = "";
foreach(string key in webRequest.Headers.Keys)
{
headers += key + "=" + webRequest.Headers[key] + " | ";
}
Debug.WriteLine(" Request Headers: " + headers);
// get response
webResponse = (HttpWebResponse)webRequest.GetResponse();
webResponse.Cookies = webRequest.CookieContainer.GetCookies(webRequest.RequestUri);
this.cookieJar.Add(webResponse.Cookies);
string cooks="";
// Print the properties of each cookie.
foreach (Cookie cook in webResponse.Cookies)
{
cooks += "\n Name = " +cook.Name + "\n Value = " +cook.Value+"\n Domain = "+cook.Domain+"\n Path = "+cook.Path+"\n Port = "+cook.Port+"\n Secure = "+cook.Secure+"\n | ";
Debug.WriteLine(" Cookies: " + cooks);

//
foreach(Cookie ck in webResponse.Cookies)
{
Debug.WriteLine(" Adding cookie: " + ck.ToString());


}

// read response stream and dump to string
Stream streamResponse = webResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);

output = streamRead.ReadToEnd();

streamRead.Close();
streamResponse.Close();

Debug.WriteLine("Received response (" + output.Length + " char(s))");


}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
System.Windows.Forms.MessageBox.Show(ex.Message, "Exception Caught");
}
finally
{
if(webResponse != null)
{
webResponse.Close();
}
}

// return the response document
return output;

}//end string MakeNewWebRequest

GeneralRe: responding to javascript in html Pin
JeromeKJerome29-Oct-04 9:27
JeromeKJerome29-Oct-04 9:27 
GeneralRe: responding to javascript in html Pin
JeromeKJerome29-Oct-04 13:41
JeromeKJerome29-Oct-04 13:41 
GeneralRe: responding to javascript in html Pin
Heath Stewart30-Oct-04 3:16
protectorHeath Stewart30-Oct-04 3:16 
GeneralRe: responding to javascript in html Pin
JeromeKJerome1-Nov-04 8:09
JeromeKJerome1-Nov-04 8:09 
GeneralRe: responding to javascript in html Pin
Heath Stewart1-Nov-04 8:11
protectorHeath Stewart1-Nov-04 8:11 
GeneralVisual Studio Add-In C# Pin
Nxsis28-Oct-04 7:54
Nxsis28-Oct-04 7:54 
GeneralRe: Visual Studio Add-In C# Pin
Heath Stewart28-Oct-04 15:40
protectorHeath Stewart28-Oct-04 15:40 
GeneralOffice Programming with C# Pin
Member 140011328-Oct-04 7:02
Member 140011328-Oct-04 7:02 
GeneralRe: Office Programming with C# Pin
Heath Stewart28-Oct-04 15:35
protectorHeath Stewart28-Oct-04 15:35 
GeneralIIS server Pin
ppp00128-Oct-04 6:41
ppp00128-Oct-04 6:41 
GeneralRe: IIS server Pin
Alex Korchemniy28-Oct-04 9:59
Alex Korchemniy28-Oct-04 9:59 
GeneralRe: IIS server Pin
Heath Stewart28-Oct-04 15:22
protectorHeath Stewart28-Oct-04 15:22 
GeneralAVI to WMV Pin
ee9903528-Oct-04 6:00
ee9903528-Oct-04 6:00 
GeneralRe: AVI to WMV Pin
Heath Stewart28-Oct-04 15:10
protectorHeath Stewart28-Oct-04 15:10 
GeneralXslTransform object protection level problem Pin
kroakdammit28-Oct-04 5:48
kroakdammit28-Oct-04 5:48 
GeneralRe: XslTransform object protection level problem Pin
Heath Stewart28-Oct-04 15:05
protectorHeath Stewart28-Oct-04 15:05 
GeneralRe: XslTransform object protection level problem Pin
kroakdammit28-Oct-04 23:24
kroakdammit28-Oct-04 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.