Trying to use REST (SharePoint) to obtain XML Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jarhead
Posts: 151
Joined: 09 Sep 2020, 12:43

Trying to use REST (SharePoint) to obtain XML

Post by jarhead » 25 Jan 2022, 13:43

Our company has a SharePoint site and I am able to successfully run various GET commands in Chrome which returns the correct XML. I'm having problems attempting to do this via AutoHotkey. I tried various portions of the below to connect and always receive a 401 UNAUTHORIZED. I'm sure the problem is I'm not sending the token (pretty sure I cannot get a token) but since it works in my browser, I assumed I could get it to work with AutoHotkey.

I sign on to my system via SSO and am connected via VPN. If this is not possible with this approach, is it possible to run the GET command through Chrome and grab the XML and then parse as needed without manually going to Chrome? Thanks.

Code: Select all

oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWhr.Open("GET", "https://MYSITE/_api/Web/Lists/GetByTitle('My Title')/items?ETC", false)
oWhr.SetRequestHeader("Content-Type", "application/json;odata=verbose")
oWhr.SetRequestHeader("Cookie", "my cookie")
oWhr.SetRequestHeader("Host", "host")
oWhr.SetRequestHeader("Referer", "referring site")
oWhr.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36")
oWhr.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
oWhr.Send()
MsgBox, % oWhr.ResponseText

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Trying to use REST (SharePoint) to obtain XML  Topic is solved

Post by amateur+ » 25 Jan 2022, 14:56

Maybe the problem is with the following:
Lexicos says: "WinHttpRequest does not use TLS 1.1 or 1.2 by default on Windows 7 and older".
So he uses Msxml2.XMLHTTP here:
https://github.com/Lexikos/AutoHotkey-Release/commit/4622287857dbbb2f23dfc91615c5b3b6650241ac
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

jarhead
Posts: 151
Joined: 09 Sep 2020, 12:43

Re: Trying to use REST (SharePoint) to obtain XML

Post by jarhead » 25 Jan 2022, 15:50

amateur+ wrote:
25 Jan 2022, 14:56
Maybe the problem is with the following:
Lexicos says: "WinHttpRequest does not use TLS 1.1 or 1.2 by default on Windows 7 and older".
So he uses Msxml2.XMLHTTP here:
https://github.com/Lexikos/AutoHotkey-Release/commit/4622287857dbbb2f23dfc91615c5b3b6650241ac
That was the problem. Thanks amateur+!

Post Reply

Return to “Ask for Help (v1)”