PC Review


Reply
Thread Tools Rating: Thread Rating: 5 votes, 4.20 average.

Simulating a Browser?

 
 
Davej
Guest
Posts: n/a
 
      7th Apr 2012
Is this commonly done? I'm thinking it would be extremely useful.
Thanks.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      7th Apr 2012
On 4/7/2012 8:26 AM, Davej wrote:
> Is this commonly done? I'm thinking it would be extremely useful.


I think it is relative common to send HTTP requests from C# code
(WebClient or HttpWebRequest). Sometimes it fake headers to completely
look like a browser.

It is also possible to embed a web browser in a web form.

Arne

 
Reply With Quote
 
 
 
 
Davej
Guest
Posts: n/a
 
      7th Apr 2012
On Apr 7, 8:04*am, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 4/7/2012 8:26 AM, Davej wrote:
>
> > Is this commonly done? I'm thinking it would be extremely useful.

>
> I think it is relative common to send HTTP requests from C#
> code (WebClient or HttpWebRequest). Sometimes it fake
> headers to completely look like a browser.
>
> It is also possible to embed a web browser in a web form.
>
> Arne


Well, I'm interested in the very simple case of communicating with a
website using a barebones page it has set aside for this automated
purpose. Is that sort of thing pretty trivial to get working? Thanks.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      7th Apr 2012
On 4/7/2012 9:18 AM, Davej wrote:
> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>> On 4/7/2012 8:26 AM, Davej wrote:
>>
>>> Is this commonly done? I'm thinking it would be extremely useful.

>>
>> I think it is relative common to send HTTP requests from C#
>> code (WebClient or HttpWebRequest). Sometimes it fake
>> headers to completely look like a browser.
>>
>> It is also possible to embed a web browser in a web form.

>
> Well, I'm interested in the very simple case of communicating with a
> website using a barebones page it has set aside for this automated
> purpose. Is that sort of thing pretty trivial to get working? Thanks.


If you can use WebClient then it is rather trivial.

WebClient wc = new WebClient();
string html = wc.DownloadString(url);

Arne

 
Reply With Quote
 
Davej
Guest
Posts: n/a
 
      11th Apr 2012
On Apr 7, 8:29*am, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 4/7/2012 9:18 AM, Davej wrote:
>
> > On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> *wrote:
> >> On 4/7/2012 8:26 AM, Davej wrote:

>
> >>> Is this commonly done? I'm thinking it would be extremely useful.

>
> >> I think it is relative common to send HTTP requests from C#
> >> code (WebClient or HttpWebRequest). Sometimes it fake
> >> headers to completely look like a browser.

>
> >> It is also possible to embed a web browser in a web form.

>
> > Well, I'm interested in the very simple case of communicating with a
> > website using a barebones page it has set aside for this automated
> > purpose. Is that sort of thing pretty trivial to get working? Thanks.

>
> If you can use WebClient then it is rather trivial.
>
> WebClient wc = new WebClient();
> string html = wc.DownloadString(url);
>
> Arne


So far I can see the file at the URL, but I can't get a response to a
post. The UploadString() example looks a bit too simple. Shouldn't the
data string have a format more like "name1=value1&name2=value2" ? Or
do I have to do some other setup stuff?

http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

Thanks.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      11th Apr 2012
On 4/11/2012 12:48 PM, Davej wrote:
> On Apr 7, 8:29 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>> On 4/7/2012 9:18 AM, Davej wrote:
>>
>>> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>>>> On 4/7/2012 8:26 AM, Davej wrote:

>>
>>>>> Is this commonly done? I'm thinking it would be extremely useful.

>>
>>>> I think it is relative common to send HTTP requests from C#
>>>> code (WebClient or HttpWebRequest). Sometimes it fake
>>>> headers to completely look like a browser.

>>
>>>> It is also possible to embed a web browser in a web form.

>>
>>> Well, I'm interested in the very simple case of communicating with a
>>> website using a barebones page it has set aside for this automated
>>> purpose. Is that sort of thing pretty trivial to get working? Thanks.

>>
>> If you can use WebClient then it is rather trivial.
>>
>> WebClient wc = new WebClient();

>
> So far I can see the file at the URL, but I can't get a response to a
> post. The UploadString() example looks a bit too simple. Shouldn't the
> data string have a format more like "name1=value1&name2=value2" ? Or
> do I have to do some other setup stuff?
>
> http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx


It is probably UploadString you need to use and you can send data
with that.

But if you want more control, then look at HttpWebRequest
(I can find an example if needed).

Arne

 
Reply With Quote
 
Davej
Guest
Posts: n/a
 
      12th Apr 2012
On Apr 11, 4:41*pm, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 4/11/2012 12:48 PM, Davej wrote:
>
>
>
>
>
>
>
>
>
> > On Apr 7, 8:29 am, Arne Vajh°j<(E-Mail Removed)> *wrote:
> >> On 4/7/2012 9:18 AM, Davej wrote:

>
> >>> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> * *wrote:
> >>>> On 4/7/2012 8:26 AM, Davej wrote:

>
> >>>>> Is this commonly done? I'm thinking it would be extremely useful.

>
> >>>> I think it is relative common to send HTTP requests from C#
> >>>> code (WebClient or HttpWebRequest). Sometimes it fake
> >>>> headers to completely look like a browser.

>
> >>>> It is also possible to embed a web browser in a web form.

>
> >>> Well, I'm interested in the very simple case of communicating with a
> >>> website using a barebones page it has set aside for this automated
> >>> purpose. Is that sort of thing pretty trivial to get working? Thanks.

>
> >> If you can use WebClient then it is rather trivial.

>
> >> WebClient wc = new WebClient();

>
> > So far I can see the file at the URL, but I can't get a response to a
> > post. The UploadString() example looks a bit too simple. Shouldn't the
> > data string have a format more like "name1=value1&name2=value2" ? Or
> > do I have to do some other setup stuff?

>
> >http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

>
> It is probably UploadString you need to use and you can send data
> with that.
>
> But if you want more control, then look at HttpWebRequest
> (I can find an example if needed).
>
> Arne


I looked up HttpWebRequest but the constructor is marked "obsolete."
See...

http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

I tried UploadString(), UploadData() and UploadValues() but the page
never seems to see the POST. It just responds with what looks like an
initial rendering.

Here is the UploadValues() code...

public String UploadValuesTest() {

WebClient client = new WebClient();

//Console.Write("\nPlease enter the URI to post data to :
");
string uriString = @"http://www.stlnetwork.net/
default.aspx";

// Create a new NameValueCollection instance to hold some
custom parameters to be posted to the URL.
NameValueCollection NameValPairs = new
NameValueCollection();

//<form name="form1" method="post" action="default.aspx"
id="form1">
//<input name="txtUserID" type="text" id="txtUserID" />
//<input name="txtPassword" type="password"
id="txtPassword" />
//<input type="submit" name="btnLogin" value="Login"
id="btnLogin" />

// Add necessary parameter/value pairs to the name/value
container.
//"txtUserID=Userabc txtPassword=Passwd1";
NameValPairs.Add("txtUserID", "Userabc");
NameValPairs.Add("txtPassword", "Passwd1");

// 'The Upload(String,NameValueCollection)' implicitly
method sets HTTP POST as the request method.
byte[] responseArray = client.UploadValues(uriString,
NameValPairs);

// Decode and display the response.
return Encoding.ASCII.GetString(responseArray);

}//end
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      12th Apr 2012
On 4/11/2012 7:01 PM, Davej wrote:
> On Apr 11, 4:41 pm, Arne Vajh°j<(E-Mail Removed)> wrote:
>> On 4/11/2012 12:48 PM, Davej wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Apr 7, 8:29 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>>>> On 4/7/2012 9:18 AM, Davej wrote:

>>
>>>>> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>>>>>> On 4/7/2012 8:26 AM, Davej wrote:

>>
>>>>>>> Is this commonly done? I'm thinking it would be extremely useful.

>>
>>>>>> I think it is relative common to send HTTP requests from C#
>>>>>> code (WebClient or HttpWebRequest). Sometimes it fake
>>>>>> headers to completely look like a browser.

>>
>>>>>> It is also possible to embed a web browser in a web form.

>>
>>>>> Well, I'm interested in the very simple case of communicating with a
>>>>> website using a barebones page it has set aside for this automated
>>>>> purpose. Is that sort of thing pretty trivial to get working? Thanks.

>>
>>>> If you can use WebClient then it is rather trivial.

>>
>>>> WebClient wc = new WebClient();

>>
>>> So far I can see the file at the URL, but I can't get a response to a
>>> post. The UploadString() example looks a bit too simple. Shouldn't the
>>> data string have a format more like "name1=value1&name2=value2" ? Or
>>> do I have to do some other setup stuff?

>>
>>> http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

>>
>> It is probably UploadString you need to use and you can send data
>> with that.
>>
>> But if you want more control, then look at HttpWebRequest
>> (I can find an example if needed).

>
> I looked up HttpWebRequest but the constructor is marked "obsolete."
> See...
>
> http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx


You use WebRequest.Create with a HTTP URL to create a HttpWebRequest.

> I tried UploadString(), UploadData() and UploadValues() but the page
> never seems to see the POST. It just responds with what looks like an
> initial rendering.


You need to be sure that you are POST'ing to the action URL
not the form URL.

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      12th Apr 2012
On 4/11/2012 7:06 PM, Arne Vajh°j wrote:
> On 4/11/2012 7:01 PM, Davej wrote:
>> On Apr 11, 4:41 pm, Arne Vajh°j<(E-Mail Removed)> wrote:
>>> On 4/11/2012 12:48 PM, Davej wrote:
>>>> On Apr 7, 8:29 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>>>>> On 4/7/2012 9:18 AM, Davej wrote:
>>>
>>>>>> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> wrote:
>>>>>>> On 4/7/2012 8:26 AM, Davej wrote:
>>>
>>>>>>>> Is this commonly done? I'm thinking it would be extremely useful.
>>>
>>>>>>> I think it is relative common to send HTTP requests from C#
>>>>>>> code (WebClient or HttpWebRequest). Sometimes it fake
>>>>>>> headers to completely look like a browser.
>>>
>>>>>>> It is also possible to embed a web browser in a web form.
>>>
>>>>>> Well, I'm interested in the very simple case of communicating with a
>>>>>> website using a barebones page it has set aside for this automated
>>>>>> purpose. Is that sort of thing pretty trivial to get working? Thanks.
>>>
>>>>> If you can use WebClient then it is rather trivial.
>>>
>>>>> WebClient wc = new WebClient();
>>>
>>>> So far I can see the file at the URL, but I can't get a response to a
>>>> post. The UploadString() example looks a bit too simple. Shouldn't the
>>>> data string have a format more like "name1=value1&name2=value2" ? Or
>>>> do I have to do some other setup stuff?
>>>
>>>> http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
>>>
>>> It is probably UploadString you need to use and you can send data
>>> with that.
>>>
>>> But if you want more control, then look at HttpWebRequest
>>> (I can find an example if needed).

>>
>> I looked up HttpWebRequest but the constructor is marked "obsolete."
>> See...
>>
>> http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

>
> You use WebRequest.Create with a HTTP URL to create a HttpWebRequest.
>
>> I tried UploadString(), UploadData() and UploadValues() but the page
>> never seems to see the POST. It just responds with what looks like an
>> initial rendering.

>
> You need to be sure that you are POST'ing to the action URL
> not the form URL.


Ooops.

I just checked your comment.

//<form name="form1" method="post" action="default.aspx" id="form1">
//<input name="txtUserID" type="text" id="txtUserID" />
//<input name="txtPassword" type="password" id="txtPassword" />
//<input type="submit" name="btnLogin" value="Login" id="btnLogin" />

If that is an ASP.NET web forms page, then it becomes a bit
tricky.

You need to send the viewstate in your POST for things
to work properly.

Look at the form source and see the hidden field.

Arne


 
Reply With Quote
 
Davej
Guest
Posts: n/a
 
      12th Apr 2012
On Apr 11, 6:09*pm, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 4/11/2012 7:06 PM, Arne Vajh°j wrote:
> > On 4/11/2012 7:01 PM, Davej wrote:
> >> On Apr 11, 4:41 pm, Arne Vajh°j<(E-Mail Removed)> wrote:
> >>> On 4/11/2012 12:48 PM, Davej wrote:
> >>>> On Apr 7, 8:29 am, Arne Vajh°j<(E-Mail Removed)> wrote:
> >>>>> On 4/7/2012 9:18 AM, Davej wrote:
> >>>>>> On Apr 7, 8:04 am, Arne Vajh°j<(E-Mail Removed)> wrote:
> >>>>>>> On 4/7/2012 8:26 AM, Davej wrote:

>
> >>>>>>>> Is this commonly done? I'm thinking it would be extremely useful..

>
> >>>>>>> I think it is relative common to send HTTP requests from C#
> >>>>>>> code (WebClient or HttpWebRequest). Sometimes it fake
> >>>>>>> headers to completely look like a browser.

>
> >>>>>>> It is also possible to embed a web browser in a web form.

>
> >>>>>> Well, I'm interested in the very simple case of communicating witha
> >>>>>> website using a barebones page it has set aside for this automated
> >>>>>> purpose. Is that sort of thing pretty trivial to get working? Thanks.

>
> >>>>> If you can use WebClient then it is rather trivial.

>
> >>>>> WebClient wc = new WebClient();

>
> >>>> So far I can see the file at the URL, but I can't get a response to a
> >>>> post. The UploadString() example looks a bit too simple. Shouldn't the
> >>>> data string have a format more like "name1=value1&name2=value2" ? Or
> >>>> do I have to do some other setup stuff?

>
> >>>>http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

>
> >>> It is probably UploadString you need to use and you can send data
> >>> with that.

>
> >>> But if you want more control, then look at HttpWebRequest
> >>> (I can find an example if needed).

>
> >> I looked up HttpWebRequest but the constructor is marked "obsolete."
> >> See...

>
> >>http://msdn.microsoft.com/en-us/libr...webrequest%28v....

>
> > You use WebRequest.Create with a HTTP URL to create a HttpWebRequest.

>
> >> I tried UploadString(), UploadData() and UploadValues() but the page
> >> never seems to see the POST. It just responds with what looks like an
> >> initial rendering.

>
> > You need to be sure that you are POST'ing to the action URL
> > not the form URL.

>
> Ooops.
>
> I just checked your comment.
>
> //<form name="form1" method="post" action="default.aspx" id="form1">
> //<input name="txtUserID" type="text" id="txtUserID" />
> //<input name="txtPassword" type="password" id="txtPassword" />
> //<input type="submit" name="btnLogin" value="Login" id="btnLogin" />
>
> If that is an ASP.NET web forms page, then it becomes a bit
> tricky.
>
> You need to send the viewstate in your POST for things
> to work properly.
>
> Look at the form source and see the hidden field.
>
> Arne


Oh! I forgot about that hidden field! So I need to downloadData() and
then send the name/value pair of the viewstate back with the other
pairs?

 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulating Exchange Server to let 3rd party app pass email to Outl =?Utf-8?B?Q3JhaWc=?= Microsoft Outlook Discussion 0 1st Feb 2005 05:27 PM
CLR error 80004005 & Simulating Mouse Clicks Ong Zihao Windows XP General 1 8th Oct 2004 06:58 PM
How to simulating lightning effects Jan Il Microsoft Powerpoint 2 22nd Mar 2004 06:45 AM
simulating RIS shoba Windows XP Setup 1 16th Dec 2003 03:09 PM
Simulating keyboard input? Mark Stier Windows XP General 0 21st Jul 2003 10:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:25 PM.