Fooling Website into thinking Im a browser

A

Alan

Hi All,

I am trying to make a few calls in succession to a website to allow me to
login and then perform a search, in a c# windows program.

wcResponse =
wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =
wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the time I
get to call 2. Bear in mind call2 can not be done at the same time as call
1. You see by the time I get to call 2 the website thinks I'm not logged in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 
J

Justin Rogers

Move your ResponseHeaders into your Headers. They are passing you some cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make sure the proper
cookies are being sent back.
 
A

Alan

Hi Thanks for your quick reply.

I tried what you said and in between calls :

wc.UploadData(....);
wc.Headers = wc.ResponseHeaders;
wc.UploadData(...);

and it just gives me an exception when I run it. Is it possible I should
only be copying the keys that are relevant. That is the session keys?


Cheers

Alan


Justin Rogers said:
Move your ResponseHeaders into your Headers. They are passing you some cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make sure the proper
cookies are being sent back.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Alan said:
Hi All,

I am trying to make a few calls in succession to a website to allow me to
login and then perform a search, in a c# windows program.

wcResponse =
wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =
wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the time I
get to call 2. Bear in mind call2 can not be done at the same time as call
1. You see by the time I get to call 2 the website thinks I'm not logged in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 
J

Justin Rogers

You should be only copying cookie headers. Headers and ResponseHeaders are both
full fledged WebHeadersCollection objects, so you'll need to use the appropriate
methods
to operate on them.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Alan said:
Hi Thanks for your quick reply.

I tried what you said and in between calls :

wc.UploadData(....);
wc.Headers = wc.ResponseHeaders;
wc.UploadData(...);

and it just gives me an exception when I run it. Is it possible I should
only be copying the keys that are relevant. That is the session keys?


Cheers

Alan


Justin Rogers said:
Move your ResponseHeaders into your Headers. They are passing you some cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make sure the proper
cookies are being sent back.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Alan said:
Hi All,

I am trying to make a few calls in succession to a website to allow me to
login and then perform a search, in a c# windows program.

wcResponse =
wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =
wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the time I
get to call 2. Bear in mind call2 can not be done at the same time as call
1. You see by the time I get to call 2 the website thinks I'm not logged in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 
A

Alan

Hi,

I tried that and it doesn't seem to work. Is there any other way of doing
this using different classes. I got it to work using XML from a browser in
ASP but obviously the browser retains the header collection in some way that
works?

Thanks again

Alan


Justin Rogers said:
You should be only copying cookie headers. Headers and ResponseHeaders are both
full fledged WebHeadersCollection objects, so you'll need to use the appropriate
methods
to operate on them.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Alan said:
Hi Thanks for your quick reply.

I tried what you said and in between calls :

wc.UploadData(....);
wc.Headers = wc.ResponseHeaders;
wc.UploadData(...);

and it just gives me an exception when I run it. Is it possible I should
only be copying the keys that are relevant. That is the session keys?


Cheers

Alan


Justin Rogers said:
Move your ResponseHeaders into your Headers. They are passing you
some
cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make sure
the
proper
cookies are being sent back.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Hi All,

I am trying to make a few calls in succession to a website to allow
me
to
login and then perform a search, in a c# windows program.

wcResponse =
wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =
wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the time I
get to call 2. Bear in mind call2 can not be done at the same time
as
call
1. You see by the time I get to call 2 the website thinks I'm not
logged
in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 
J

Justin Rogers

You can use WebRequest with a CookieContainer attached. The CookieContainer
will hold and parse your return cookies.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Alan said:
Hi,

I tried that and it doesn't seem to work. Is there any other way of doing
this using different classes. I got it to work using XML from a browser in
ASP but obviously the browser retains the header collection in some way that
works?

Thanks again

Alan


Justin Rogers said:
You should be only copying cookie headers. Headers and ResponseHeaders are both
full fledged WebHeadersCollection objects, so you'll need to use the appropriate
methods
to operate on them.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Alan said:
Hi Thanks for your quick reply.

I tried what you said and in between calls :

wc.UploadData(....);
wc.Headers = wc.ResponseHeaders;
wc.UploadData(...);

and it just gives me an exception when I run it. Is it possible I should
only be copying the keys that are relevant. That is the session keys?


Cheers

Alan


Move your ResponseHeaders into your Headers. They are passing you some
cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make sure the
proper
cookies are being sent back.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Hi All,

I am trying to make a few calls in succession to a website to allow me
to
login and then perform a search, in a c# windows program.

wcResponse =

wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =

wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the
time I
get to call 2. Bear in mind call2 can not be done at the same time as
call
1. You see by the time I get to call 2 the website thinks I'm not logged
in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 
A

Alan

Thanks Justin I have now resolved the problem by doing it the original way
you specified. I wasn't setting the format of the cookies correctly.

Thanks for all your help.


Cheers

Alan


Justin Rogers said:
You can use WebRequest with a CookieContainer attached. The CookieContainer
will hold and parse your return cookies.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Alan said:
Hi,

I tried that and it doesn't seem to work. Is there any other way of doing
this using different classes. I got it to work using XML from a browser in
ASP but obviously the browser retains the header collection in some way that
works?

Thanks again

Alan


Justin Rogers said:
You should be only copying cookie headers. Headers and
ResponseHeaders
are both
full fledged WebHeadersCollection objects, so you'll need to use the appropriate
methods
to operate on them.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Hi Thanks for your quick reply.

I tried what you said and in between calls :

wc.UploadData(....);
wc.Headers = wc.ResponseHeaders;
wc.UploadData(...);

and it just gives me an exception when I run it. Is it possible I should
only be copying the keys that are relevant. That is the session keys?


Cheers

Alan


Move your ResponseHeaders into your Headers. They are passing you some
cookies
most likely
and you need to store these across calls. Use the sample program under
ResponseHeaders property
to investigate the headers associated with the response to make
sure
the
proper
cookies are being sent back.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Hi All,

I am trying to make a few calls in succession to a website to
allow
me
to
login and then perform a search, in a c# windows program.

wcResponse =
wc.UploadData("http://www.website.com/login?service2&user=joebloggs&blah","P
OST", new byte[]{});

wcResponse =
wc.UploadData("http://www.website.com/login?service3&search="+search_string,
"POST", new byte[]{});


However when using WebClient there is no concept of any session state
between calls that would let the website think I am logged in by the
time I
get to call 2. Bear in mind call2 can not be done at the same
time
as
call
1. You see by the time I get to call 2 the website thinks I'm
not
logged
in.
e.t.c.


Is there anyway of doing this?

Cheers

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top