+ Reply to Thread
Results 1 to 23 of 23

xml or winhttp - Can I send a POST request with a lot of parameters?

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    xml or winhttp - Can I send a POST request with a lot of parameters?

    Hi guys and girls,

    first of all - my apologies for not being more clear on this.
    I am working with some internal sites with sensitive data, so can't show specific examples.

    I log onto an internal website which and select some options then click submit.
    Then a table is shown, which is generated from a POST request to that site.
    This POST request has a header including a very long cookie string.
    website inspector gives me the following info:

    Host: (cant.tell.you.sorry)
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0
    Accept: text/plain, */*; q=0.01
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    DNT: 1
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    X-Requested-With: XMLHttpRequest
    Referer: (cant.tell.you.sorry)
    Content-Length: 2646
    Cookie: (1545 characters what looks partially base64 encoded data – with session id, session time etc.)
    Connection: keep-alive
    Pragma: no-cache
    Cache-Control: no-cache

    then there's a request body with 2646 characters of parameters, which are basically the options I selected and submit.

    Would it be possible for me to send all this data from VBA in a POST request and get the data that fills the table back?
    I've been trying to find the answer, but most WinHTTP or XML vba queries I find that handle a POST request, don't send along content and cookie information.

    Again, sorry to be vague, but any help or pointers are appreciated!

    Cheers,

    Jasper

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    *one small bump before this one ends up in oblivion*

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    WinHTTP sends cookie information automatically XMLHTTP doesn't. However, for it to have a copy of the cookie, you will need to log in through WinHTTP, you can then do the second request for the table

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Hi Kyle,

    thanks for the reply as always!
    How do I 'capture' the cookie and send it with the second request? Or is that done automatically?
    Also - how can I send the request body along with the parameters (~2600 bytes long)
    Those never change, so I can put into the vba code, but how do I send them along with my request?

    Thanks,

    Jasper

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    It's done automatically.

    You just pass them into the Send method when making the call:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Hi Kyle (and anyone else who might give me some guidance ),

    sorry for the late reply.

    If I use the POST request with the POST body, it will give the result:
    <NotAuthorizedException/>

    I assume that is because I immediately go to the second url and not through the first url beforehand (the one that gives me the cookie).

    If I try something like the code below, it won't work - what do I need to do to get the cookie first from URL A and then pass it on to URL b?
    The first url is something like:

    http://www.company.com/stuff/dosomet...arehouseID=XXX

    then the second url is something like:

    http://www.company.com/stuff/dometrics.do

    but the following (obviously) doesn't work - any hints on what to do to get it to work?

    Please Login or Register  to view this content.
    Thanks,

    Jasper

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    You need to log in with Winhttp. So you need to do 2 requests, one to log in and one to get the data.

  8. #8
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    How would I adjust my code to implement that?

    If I just add a send as below, it still gives me the same result...

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    I've no idea since I don't know what your login page is like - though presumably you don't log in with Get? You are also sending no params in the post body

  10. #10
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    OK, I'll try and dive into it - seems there's a lot more going on in the background.
    Actually, the 'body' is a string that holds the parameters (I set that string before this part of code).

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    It's easy just replicate the request that's fired when you log in, just as you would for any other query. You can then run the second request

  12. #12
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Hi Kyle,

    it's easy if you know how
    Although I've been playing around with web requests (mostly XML) and getting web data via VBA for a while now, I still feel like I am not even scratching the surface with my knowledge.

    If I look at network activity in firefox on opening the first url (http://www.company.com/stuff/dosomet...arehouseID=XXX) - I get the following :

    200 GET dosomething.html?warehouseID=XXX www.company.com html
    304 GET something.css internal.company.com css
    304 GET something.js internal.company.com js
    200 GET login www.company.com json
    200 GET login www.company.com json
    200 GET login www.company.com json
    200 GET login www.company.com json

    only after that it will go to my url2

    I got no clue how to capture everything from entering the first url until the second url (where I go to after clicking a button).
    So, not that easy

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    How do you log in?

  14. #14
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Basically it looks at my domain name.
    I don't have to login with username/pass anywhere - it's just based on my windows login name, but nowhere do I specifically send that to the site.

    I get data from other internal sites that are only visible to certain users and check my username and there I never have to log in manually either nor in VBA.

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    In that case it's a bit different, chances are you are using NTLM authentication, winhttp supports this, have a read here: https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx

    With an example: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

  16. #16
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Ok, I read those pages and get most of it.
    I'm dealing with a challenge <> response authentication and am trying to understand how to implement Kerberos authentication in my code.

    The examples given on the page are in C / VB though, so it's taking me a bit longer
    Last edited by JasperD; 04-01-2015 at 10:47 AM.

  17. #17
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Have you found out what sort of authentication you are using? Is it NTLM?

    Do a debug.print of .GetAllResponseHeaders and see what it says

  18. #18
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    It's "negotiate" (so might actually be NTLM - how can I be sure?)

    From getallresponseheaders:

    Connection: keep-alive
    Date: Wed, 01 Apr 2015 14:54:47 GMT
    Content-Length: 27
    Content-Type: text/xml
    Server: Server
    WWW-Authenticate: Negotiate
    WWW-Authenticate: Basic realm=""
    Last edited by JasperD; 04-01-2015 at 11:00 AM.

  19. #19
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Ok, so you're using Negotiate rather than NTLM, try:
    Please Login or Register  to view this content.
    Failing that, it looks like Basic Authentication is supported as well
    Last edited by Kyle123; 04-01-2015 at 11:08 AM.

  20. #20
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    That works!! How can you always make it look so easy...?
    Step #1 is a success.


    However, if after that I add:

    Please Login or Register  to view this content.
    I don't get an unauthorized, but instead a message telling me:

    {"errorMessage":"warehouseId is not provided","success":false}

    However, the warehouseId is the first part of the body that I send (warehouseId=xxx&....) - any ideas on where to look next?

  21. #21
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Turns out that it still had an old warehouse id in the cache / cookie, so now it works! (YAY!!)
    MANY thanks to Kyle for the constant and great support.

    One last question before I set this as solved: Can I flush the cookies/cache each time I run the code? So it won't keep looking for older warehouse IDs?
    Or should that be done automatically?

    Thanks again!!

  22. #22
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    I can't remember off hand, but if you manually set a request header for the cookie with an empty string I suspect it will override any existing cookies


    Sent from my iPhone using Tapatalk

  23. #23
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: xml or winhttp - Can I send a POST request with a lot of parameters?

    Marking this thread as solved.

    Many, MANY thanks to Kyle for sticking with me and persisting in finding a solution.
    It's much appreciated - I owe you many beers!

+ 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. I am very new to VBA but need some VBA code to send a meeting request
    By angusmcdw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2014, 12:53 PM
  2. Replies: 3
    Last Post: 08-28-2013, 06:53 AM
  3. [SOLVED] send parameters to a batch file with the shell command
    By Marcos in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2006, 03:00 PM
  4. Replies: 2
    Last Post: 02-28-2005, 11:06 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