Simulating a Browser?

Discussion in 'Microsoft C# .NET' started by Davej, Apr 7, 2012.

  1. Davej

    Davej Guest

    Is this commonly done? I'm thinking it would be extremely useful.
    Thanks.
     
    Davej, Apr 7, 2012
    #1
    1. Advertisements

  2. Davej

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Apr 7, 2012
    #2
    1. Advertisements

  3. Davej

    Davej Guest

    On Apr 7, 8:04 am, Arne Vajhøj <> 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.
     
    Davej, Apr 7, 2012
    #3
  4. Davej

    Arne Vajhøj Guest

    On 4/7/2012 9:18 AM, Davej wrote:
    > On Apr 7, 8:04 am, Arne Vajhøj<> 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
     
    Arne Vajhøj, Apr 7, 2012
    #4
  5. Davej

    Davej Guest

    On Apr 7, 8:29 am, Arne Vajhøj <> wrote:
    > On 4/7/2012 9:18 AM, Davej wrote:
    >
    > > On Apr 7, 8:04 am, Arne Vajhøj<>  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/library/d0d3595k(v=vs.110).aspx

    Thanks.
     
    Davej, Apr 11, 2012
    #5
  6. Davej

    Arne Vajhøj Guest

    On 4/11/2012 12:48 PM, Davej wrote:
    > On Apr 7, 8:29 am, Arne Vajhøj<> wrote:
    >> On 4/7/2012 9:18 AM, Davej wrote:
    >>
    >>> On Apr 7, 8:04 am, Arne Vajhøj<> 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/library/d0d3595k(v=vs.110).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
     
    Arne Vajhøj, Apr 11, 2012
    #6
  7. Davej

    Davej Guest

    On Apr 11, 4:41 pm, Arne Vajhøj <> wrote:
    > On 4/11/2012 12:48 PM, Davej wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Apr 7, 8:29 am, Arne Vajhøj<>  wrote:
    > >> On 4/7/2012 9:18 AM, Davej wrote:

    >
    > >>> On Apr 7, 8:04 am, Arne Vajhøj<>    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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v=vs.110).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
     
    Davej, Apr 12, 2012
    #7
  8. Davej

    Arne Vajhøj Guest

    On 4/11/2012 7:01 PM, Davej wrote:
    > On Apr 11, 4:41 pm, Arne Vajhøj<> wrote:
    >> On 4/11/2012 12:48 PM, Davej wrote:
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>> On Apr 7, 8:29 am, Arne Vajhøj<> wrote:
    >>>> On 4/7/2012 9:18 AM, Davej wrote:

    >>
    >>>>> On Apr 7, 8:04 am, Arne Vajhøj<> 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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v=vs.110).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
     
    Arne Vajhøj, Apr 12, 2012
    #8
  9. Davej

    Arne Vajhøj Guest

    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<> wrote:
    >>> On 4/11/2012 12:48 PM, Davej wrote:
    >>>> On Apr 7, 8:29 am, Arne Vajhøj<> wrote:
    >>>>> On 4/7/2012 9:18 AM, Davej wrote:
    >>>
    >>>>>> On Apr 7, 8:04 am, Arne Vajhøj<> 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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v=vs.110).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
     
    Arne Vajhøj, Apr 12, 2012
    #9
  10. Davej

    Davej Guest

    On Apr 11, 6:09 pm, Arne Vajhøj <> 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<> wrote:
    > >>> On 4/11/2012 12:48 PM, Davej wrote:
    > >>>> On Apr 7, 8:29 am, Arne Vajhøj<> wrote:
    > >>>>> On 4/7/2012 9:18 AM, Davej wrote:
    > >>>>>> On Apr 7, 8:04 am, Arne Vajhøj<> 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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v....

    >
    > > 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?
     
    Davej, Apr 12, 2012
    #10
  11. Davej

    Arne Vajhøj Guest

    On 4/11/2012 7:22 PM, Davej wrote:
    > On Apr 11, 6:09 pm, Arne Vajhøj<> 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<> wrote:
    >>>>> On 4/11/2012 12:48 PM, Davej wrote:
    >>>>>> On Apr 7, 8:29 am, Arne Vajhøj<> wrote:
    >>>>>>> On 4/7/2012 9:18 AM, Davej wrote:
    >>>>>>>> On Apr 7, 8:04 am, Arne Vajhøj<> 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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v...

    >>
    >>> 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.

    >
    > 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?


    Yes.

    Arne
     
    Arne Vajhøj, Apr 12, 2012
    #11
  12. Davej

    Davej Guest

    On Apr 11, 6:30 pm, Arne Vajhøj <> wrote:
    > On 4/11/2012 7:22 PM, Davej wrote:
    > > On Apr 11, 6:09 pm, Arne Vajhøj<>  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<>  wrote:
    > >>>>> On 4/11/2012 12:48 PM, Davej wrote:
    > >>>>>> On Apr 7, 8:29 am, Arne Vajhøj<>  wrote:
    > >>>>>>> On 4/7/2012 9:18 AM, Davej wrote:
    > >>>>>>>> On Apr 7, 8:04 am, Arne Vajhøj<>  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'tthe
    > >>>>>> 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/library/d0d3595k(v=vs.110).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/library/system.net.httpwebrequest(v....

    >
    > >>> 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.

    >
    > > 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?

    >
    > Yes.
    >
    > Arne


    Bingo. That was it. Much thanks! Should have been obvious to me but I
    just wasn't thinking to look for hidden fields.
     
    Davej, Apr 12, 2012
    #12
  13. Davej

    Davej Guest

    On Apr 11, 6:51 pm, Davej <> wrote:
    > On Apr 11, 6:30 pm, Arne Vajhøj <> wrote:
    > > On 4/11/2012 7:22 PM, Davej wrote:
    > > > On Apr 11, 6:09 pm, Arne Vajhøj<>  wrote:
    > > >> On 4/11/2012 7:06 PM, Arne Vajhøj wrote:
    > > >>> On 4/11/2012 7:01 PM, Davej wrote:

    >
    > > >>>> I tried UploadString(), UploadData() and UploadValues() but the page
    > > >>>> never seems to see the POST. It just responds with what looks likean
    > > >>>> 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.

    >
    > > > 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?

    >
    > > Yes.

    >
    > > Arne

    >
    > Bingo. That was it. Much thanks! Should have been obvious to me but I
    > just wasn't thinking to look for hidden fields.


    I have some working test code now. The routines necessary to extract
    the two keys in the hidden fields were rather bothersome. Now I need
    to figure out how to implement the "non blocking" methods because this
    process is pretty slow.
     
    Davej, Apr 12, 2012
    #13
  14. Davej

    Arne Vajhøj Guest

    On 4/12/2012 2:30 PM, Davej wrote:
    > On Apr 11, 6:51 pm, Davej<> wrote:
    >> On Apr 11, 6:30 pm, Arne Vajhøj<> wrote:
    >>> On 4/11/2012 7:22 PM, Davej wrote:
    >>>> On Apr 11, 6:09 pm, Arne Vajhøj<> wrote:
    >>>>> On 4/11/2012 7:06 PM, Arne Vajhøj wrote:
    >>>>>> On 4/11/2012 7:01 PM, Davej wrote:

    >>
    >>>>>>> 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.

    >>
    >>>> 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?

    >>
    >>> Yes.

    >>
    >> Bingo. That was it. Much thanks! Should have been obvious to me but I
    >> just wasn't thinking to look for hidden fields.

    >
    > I have some working test code now. The routines necessary to extract
    > the two keys in the hidden fields were rather bothersome.


    Yes - calling web forms pages programmatically is just cumbersome.

    > Now I need
    > to figure out how to implement the "non blocking" methods because this
    > process is pretty slow.


    Well - you can either use threads/threadpool or go for the asynch
    methods.

    Arne
     
    Arne Vajhøj, Apr 12, 2012
    #14
  15. Davej

    Davej Guest

    On Apr 12, 4:46 pm, Arne Vajhøj <> wrote:
    > On 4/12/2012 2:30 PM, Davej wrote:
    > > On Apr 11, 6:51 pm, Davej<>  wrote:
    > >> On Apr 11, 6:30 pm, Arne Vajhøj<>  wrote:
    > >>> On 4/11/2012 7:22 PM, Davej wrote:
    > >>>> On Apr 11, 6:09 pm, Arne Vajhøj<>    wrote:
    > >>>>> On 4/11/2012 7:06 PM, Arne Vajhøj wrote:
    > >>>>>> On 4/11/2012 7:01 PM, Davej wrote:

    >
    > >>>>>>> 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.

    >
    > >>>> 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?

    >
    > >>> Yes.

    >
    > >> Bingo. That was it. Much thanks! Should have been obvious to me but I
    > >> just wasn't thinking to look for hidden fields.

    >
    > > I have some working test code now. The routines necessary to extract
    > > the two keys in the hidden fields were rather bothersome.

    >
    > Yes - calling web forms pages programmatically is just cumbersome.
    >
    > > Now I need to figure out how to implement the "non blocking"
    > > methods because this process is pretty slow.

    >
    > Well - you can either use threads/threadpool or go for the asynch
    > methods.
    >
    > Arne


    Are there other better schemes that I should be investigating? I have
    read a little about web services, but they seem to be all about
    exchanging XML data. Compared to that the various WebClient methods
    seem pretty powerful. I want to be able to upload and download jpg
    files and some text records. It looks like the WebClient methods will
    cover that. Thanks.
     
    Davej, Apr 12, 2012
    #15
  16. Davej

    Arne Vajhøj Guest

    On 4/12/2012 6:23 PM, Davej wrote:
    > On Apr 12, 4:46 pm, Arne Vajhøj<> wrote:
    >> On 4/12/2012 2:30 PM, Davej wrote:
    >>> On Apr 11, 6:51 pm, Davej<> wrote:
    >>>> On Apr 11, 6:30 pm, Arne Vajhøj<> wrote:
    >>>>> On 4/11/2012 7:22 PM, Davej wrote:
    >>>>>> On Apr 11, 6:09 pm, Arne Vajhøj<> wrote:
    >>>>>>> On 4/11/2012 7:06 PM, Arne Vajhøj wrote:
    >>>>>>>> On 4/11/2012 7:01 PM, Davej wrote:

    >>
    >>>>>>>>> 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.

    >>
    >>>>>> 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?

    >>
    >>>>> Yes.

    >>
    >>>> Bingo. That was it. Much thanks! Should have been obvious to me but I
    >>>> just wasn't thinking to look for hidden fields.

    >>
    >>> I have some working test code now. The routines necessary to extract
    >>> the two keys in the hidden fields were rather bothersome.

    >>
    >> Yes - calling web forms pages programmatically is just cumbersome.
    >>
    >>> Now I need to figure out how to implement the "non blocking"
    >>> methods because this process is pretty slow.

    >>
    >> Well - you can either use threads/threadpool or go for the asynch
    >> methods.

    >
    > Are there other better schemes that I should be investigating?


    I don't think so.

    For HTML parsing you could look at HTML Agility Pack.

    > I have
    > read a little about web services, but they seem to be all about
    > exchanging XML data.


    Or at least a format intended for an application and not a browser.

    > Compared to that the various WebClient methods
    > seem pretty powerful. I want to be able to upload and download jpg
    > files and some text records. It looks like the WebClient methods will
    > cover that.


    And if WebClient is not flexible enough then you can fallback to
    HttpWebRequest.

    Arne
     
    Arne Vajhøj, Apr 13, 2012
    #16
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bwahahahaha

    Simulating mouse movements

    bwahahahaha, Oct 15, 2003, in forum: Microsoft C# .NET
    Replies:
    6
    Views:
    232
    Michael Bray
    Oct 15, 2003
  2. Ray Mitchell

    Simulating sscanf parsing in C#

    Ray Mitchell, Nov 1, 2003, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    576
    AlexS
    Nov 2, 2003
  3. Mark Rae

    Simulating the File Properties dialog

    Mark Rae, Mar 15, 2004, in forum: Microsoft C# .NET
    Replies:
    6
    Views:
    255
    Mark Rae
    Mar 17, 2004
  4. A Waterfall That Barks

    AI and .NET: Simulating a Swarm Algorithm in C#

    A Waterfall That Barks, May 12, 2004, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    235
    Peter Ammon
    May 12, 2004
  5. Richard Beacroft

    Simulating a magnetic swipe

    Richard Beacroft, Jun 15, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    253
    William Stacey [MVP]
    Jun 15, 2004
Loading...

Share This Page