+ Reply to Thread
Results 1 to 4 of 4

Post part of Form Data while doing xmlhttp request

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Post part of Form Data while doing xmlhttp request

    Hello everyone

    In the following code I am trying to use the POST method and I have noticed it is using the Form Data which has a very very long text
    Please Login or Register  to view this content.
    I am trying to search for ID 270022102796 which is in this part of the form data ctl00%24m%24g_cca43156_d33a_4ef1_8782_2c3c7a4eeaf3%24ctl00%24txtCivilID=270022102796. In the rendered html, I couldn't find the expected output for this entry which should be in the element which ID is ctl00_m_g_cca43156_d33a_4ef1_8782_2c3c7a4eeaf3_ctl00_lblResult

    Is it possible to use just part of the form data? And if possible why didn't I got the correct HTML document?

    To make the issue clear, I have a solution using IE

    Please Login or Register  to view this content.
    And Here's another solution using selenium
    Please Login or Register  to view this content.
    In cell A2 >> 270022102796
    In cell A3 >> 260091701856
    for testing purpose

    The thread is posted too at this link
    https://stackoverflow.com/questions/57036490
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Post part of Form Data while doing xmlhttp request

    Since this is ASPX page and post-back method, few parameters of form data is required to get response/content via post.

    As mentioned by QHarr in StackOverflow thread...
    At minimum you'd need.
    1. _ViEWSTATE - This parameter is vital info in order to scrape data. Basically it stores page status and control values.
    2. _VIEWSTATEGENERATOR - I'm not 100% on this, but as I understand it, this is ID of control that generated view state.
    3. _EVENTVALIDATION - This ensures that values received by the server process in a POST are known good values. Basically security feature that prevents backdoor actions.
    4. ctl00$m$g_cca43156_d33a_4ef1_8782_2c3c7a4eeaf3$ctl00$txtCivilID - The textbox you are entering value to.
    5. ctl00$m$g_cca43156_d33a_4ef1_8782_2c3c7a4eeaf3$ctl00$btnSearch - Control that execute search.

    Other values/parameters may be used by server, but may just use default values and/or return values you are not interested in.

    So, you'd need to parse form data based on these parameters and experiment by adjusting other parameters as needed.

    However, in general, it is not easy to emulate all the security and parameters. For an instance, _VIEWSTATE is going to be different each and every time page is viewed.
    You have a code that works with IE automation and using Selenium. It would be more robust and will cause less of issue than trying to emulate browser interaction with ASP.NET.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Post part of Form Data while doing xmlhttp request

    Thanks a lot for your informative reply. I have a problem concatenating the parameters you mentioned. I got the line in red all the time and I am confused
    As for the _VIEWSTATE you told that it will be different each time .. Isn't there a way or workaround to overcome this part?
    I know solutions of IE and Selenium working well but it is somewhat slow as for me ...

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Post part of Form Data while doing xmlhttp request

    To create the long form data string. You will need to construct it in stages (i.e. concatenate short segment at a time to build final string).

    .. Isn't there a way or workaround to overcome this part?
    Well, there are ways, but then you'll be basically emulating what the browser does. So I really don't see a point here.
    To really understand what a viewstate is, refer to link below.
    https://weblogs.asp.net/infinitieslo...ding-Viewstate

    My personal opinion is that it's not worth all the trouble.

    EDIT: Oh and I'm pretty sure I showed you how to construct very long form data string in another forum.
    EDIT2: Here's the link. https://chandoo.org/forum/threads/co...3/#post-223906
    Last edited by CK76; 07-15-2019 at 04:44 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. XMLHTTP POST Request - Input Parameter Variable Max Length
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2019, 06:24 AM
  2. XMLHTTP Login Post
    By greensky2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2017, 04:42 PM
  3. sending CHECKED attribute of a form via XMLHTTP
    By vientito in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2013, 11:44 AM
  4. send login details to web form using Microsoft.XMLHTTP
    By robert101083 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-10-2013, 07:33 AM
  5. Use XMLHTTP to log on website and then post data
    By tonyibm in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-19-2013, 09:03 AM
  6. Submit Web Form Search and Save Source Code using xmlhttp
    By brianblack2b in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2012, 01:57 PM
  7. XMLHTTP.ResponseBody / XMLHTTP.Responsetext Paste into Excel Sheet
    By gophins in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-11-2012, 11:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1