I am currently using vba for data extraction,now i want to use chrome profile in http request so that system will use existing login.My existing code is given below.My basic requirement is login should be used from google profile as site require login on each request.
url = "https://www-scopus-com.ezproxy.bond.edu.au/record/display.uri?eid=2-s2.0-84959878702&origin=resultslist&sort=plf-f&src=s&nlo=&nlr=&nls=&sid=26b13cfb6e420c1f731d3b512a1ba29e&sot=a&sdt=a&cluster=scopubyr%2c%222014%22%2ct%2bscoexactsrctitle%2c%22Journal+Of+Islamic+Accounting+And+Business+Research%22%2ct&sl=64&s=SRCTITLE+%28%22Journal+of+Islamic+Accounting+and+Business+Research%22%29&relpos=9&citeCnt=21&searchTerm="
Dim html As MSHTML.HTMLDocument, xml As Object
Set html = New MSHTML.HTMLDocument
Set xml = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xml.Open "GET", url, False
xml.SetRequestHeader "User-Agent", "chrome", "Profile", "C:\Users\ts\AppData\Local\Google\Chrome\User Data\Default"
xml.Send
'Sleep 5000
html.body.innerHTML = xml.ResponseText
Related
My goal is to send a text message in VBA with Twilio's API by using WinHttpRequest and a POST call.
I put together a custom call using the WinHttpRequest for a basic SMS message and that worked. I can send text messages just fine.
But then I tried adding the MediaURL to the data, and it ignored the URL (no image attached to SMS). I confirmed the URL was valid by testing it in the Visual Studio project and it was able to send just fine.
I went back and tried sending a test image on twilio's servers and it works. I copied the same image to a server and it won't work.
WORKS
HTTPReq.send ("Body=Hi Brent, Hello From Me!&From=+1XXXXXXXXXX&To=+1XXXXXXXXX&MediaUrl=https://demo.twilio.com/owl.png")
DOESN'T WORK
HTTPReq.send ("Body=Hi Brent, Hello From ME!&From=+1XXXXXXXXXX&To=+1XXXXXXXXXX&MediaURL=https://smarttanktester.com/wp-content/uploads/2018/10/owl.png")
(Phone numbers removed).
I tested with a few more images from their site and they work.
So it appears that URLs external to their server are being ignored. My guess is that I have something configured wrong from my end.
Here is my code.
TargetURL = "https://api.twilio.com/2010-04-01/Accounts/XXX/Messages"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.Open "POST", TargetURL, False
HTTPReq.setRequestHeader "Accept", "application/json"
temp = "Basic " & EncodeBase64
HTTPReq.setRequestHeader "Authorization", temp
HTTPReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTPReq.send ("Body=Hi Brent, Hello From Me!&From=+1XXXXXXXXXX&To=+1XXXXXXXXXX&MediaURL=https://smarttanktester.com/wp-content/uploads/2018/10/owl.png")
Any help is greatly appreciated.
I need to use jira Rest API to fetch some content in an excel sheet.The problem is that the server is siteminder enabled.I am using this codeproject article as reference (.http://www.codeproject.com/Articles/80314/How-to-Connect-to-a-SiteMinder-Protected-Resource ) but still cannot get to the past the siteminder login page
For reference,my code is as follows:
Dim http As New WinHttp.WinHttpRequest
http.Option(WinHttpRequestOption_EnableRedirects) = False
url = "http://example.com"
' Launch the HTTP request
http.Open "GET", url, False
http.Send
target=http.GetResponseHeaders("location")//get the target url for post
Cookie=""
postData="USER="&HttpUtility.UrlEncode(username)&"&PASSWORD="&password
http.Open "POST", target, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Cookie", Cookie
http.Send postData
The first http request takes me to the userlogin page of siteminder but the user doesn't get authenticated after the post request.I receive the error login page.Any suggestion as to how to get the user authenticated?
I'm tryng to make a HTTP request from VB for Applications ( VBA)
that should have been simple:
URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.Send
MsgBox xhr.responseText
BUT I'm behind a proxy server which require basic auth (base64).
How to set the credentials in VBA ?
(something equivalent to : myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials)
If this is not possible, how to solve the issue with another approach ?
Thanks !
You'd need the setProxyCredentials method. I don't have a proxy to test, but this should do the trick:
URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.setProxy 2, "192.168.0.222:8080"
xhr.setProxyCredentials "your_username" , "password_for_username"
xhr.Send
MsgBox xhr.responseText
Taken from This Question which points out the 2 argument is a version number that you may need to change.
I have a current web site that captures data send via querystring
I would like to repost this data to a different API using HTTP GET and capture the response from that site. Response.Redirect works but can not read the results of that post.
This sample code should get you started. It requests the page from a url with querystring values passed, and stores the response in a variable then response.write's the contents.
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", "http://www.test.com/test.asp?var1=val1", false
objXML.Send ""
strResponse = objXML.ResponseText
Response.Write strResponse
I am writing a set of VBA macros in which it uses the XMLHTTP object to send asynchronous requests to a server. I am sending Basic Authentication with:
XMLHttpReq.setRequestHeader "Authorization","Basic " & Base64EncodedUserPass
This works great the first time.
But if the user changes their userid/password, even if the code creates a brand new XMLHttpReq object and sets this header to the new information, it logs in to the server as the first user, presumably from cached credentials.
How can I cause the code to "forget" that I have logged in before, and re-authorize?
Edit as requested, the relevant part of the code; it really isn't very complicated:
myURL = "http://my.domain.com/myscript.cgi"
Dim oHttp As New MSXML2.XMLHTTP
oHttp.Open "POST", myURL, False
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded'"
oHttp.setRequestHeader "Authorization","Basic " & Base64EncodedUsernamePassword
oHttp.send "PostArg1=PostArg1Value"
Result = oHttp.responseText
These questions have been discussed in many ways due to major browsers different implementations of caching methods.
I will give you what worked for me and then the sources I found on this feature.
The only solution I could came across was to force the browser to not cache the request.
myURL = "http://my.domain.com/myscript.cgi"
Dim oHttp As New MSXML2.XMLHTTP
oHttp.Open "POST", myURL, False
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded'"
oHttp.setRequestHeader("Cache-Control", "no-cache");
oHttp.setRequestHeader("Pragma", "no-cache");
oHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
oHttp.setRequestHeader "Authorization","Basic " & Base64EncodedUsernamePassword
oHttp.send "PostArg1=PostArg1Value"
Result = oHttp.responseText
It seems that Cache-Control works on most browsers and Pragma only on Firefox and not IE (don't know why...)
If-Modified-Since is used for IE, since IE uses different settings in his own algorithm to determine whether or not the request should be cached. XMLHttpRequest seem to not be treated as the same as HTTP responses.
Careful : With this code you will need username and password each time a new object is created. Maybe you should create a new object, instantiate it once and then destroy it after use. In between you would have all your requests handled in different functions with only one authentication.
Sources
MSDN setRequestHeader Method
MSDN IXMLHTTPRequest
XMLHTTPREQUEST CACHING TESTS
XMLHttpRequest and Caching