How to retrieve URL dynamically? - vbscript

I am using a webservice in my project. I am giving URL like this:
WebServicename.asmx/Methodname
Locally I used webservice in VBScript and it is running good. But when I deployed same code in a server the webservice is not running. So before that webservice I want to give full URL. So for that reason I want to get that URL dynamically and add before of my URL.

I am writing Vb script and I call webservice like this
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
'Msgbox("Calling WebService To Approve Leave")
strEnvelope ="varCarrierType="&varCarrierType &varCarrierID& "&Filename="&Filename& "&varC22Cnt="&varC22Cnt&"&varCurrentDateTime="&varCurrentDateTime&"&varTotalCommissionAmt="&varTotalCommissionAmt&"&vpath="&vpath
oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
call oXMLHTTP.open("POST","/VBScriptService.asmx/InsertDBDetails",False)
call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
call oXMLHTTP.send(strEnvelope)
MsgBox "COM File successfully generated from the Template given. Verify the output file in " & vpath,0, "Com File Generation"
MsgBox "Page About to Refresh, Click ok to proceed", 0, "ComPage Refresh"
Set wShell=CreateObject("WScript.Shell")
wShell.SendKeys "{F5}"

Related

Retrieving a image file from a website by passing credentials

Using Visual Basic 6.0. My code needs to pull picture images from a website and download to c:\temp location.
To access the website we need to pass credentials; upon successful login the images automatically downloads. Sample code:
'retrieve image from URL
getURL = "http://mrldata#abc.com:8080/mrldata/compounds/" & lnumber & ".jpg?"
Randomize
localFile = "C:\temp\" & Hour(Now()) & Minute(Now()) & Second(Now()) & Int(Rnd * 10) & ".jpg"
CopyURLToFile getURL, localFile
How can credentials be passed in order to access the website?

How to test a Restful service which returns a JSON Response using UFT?

I have been using QTP 11 and we have had to migrate to UFT 12.02 now.
We have some REST services which have come for testing and problem is that it gives a JSON Response when done manually. I have not worked on C# before so is there any way I can configure this service using UFT API and validate the response using VB script which I am accustomed to.
I tried the following:
Dim lib, url, xmlHttp, json, JsonConvert, xmlDoc
lib = "C:\Bin\Net35\Newtonsoft.Json.dll"
url = "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "POST", url, False
xmlHttp.send
json = "{ ""?xml"": { ""#version"": ""1.0"", ""#standalone"": ""no"" }, ""root"":" & xmlHttp.responseText & "}"
Set JsonConvert = DOTNetFactory.CreateInstance("Newtonsoft.Json.JsonConvert", lib)
Set xmlDoc = JsonConvert.DeserializeXmlNode(json)
MsgBox xmlDoc.InnerXml
But I do not have the dll available with me, I am unable to test the URL with this.
If this is the correct way then can anyone let me know how can I get this dll installed.
UFT internally uses Newtonsoft.Json framework (like many other HPE products), so it already includes such DLL.
You just need to update the path to point to UFT\bin directory, which by default is:
lib = "C:\Program Files (x86)\HP\Unified Functional Testing\bin\Newtonsoft.Json.dll"
Now, from API testing perspective, you can use checkpoints to validate the results. See Image

saving file with download prompt with vbscript

I'm using VBscript to use IE to open a webpage - login - and save some data to a file.
Why use IE?
- I can use VBScript to interact with the webpage
- The webpage uses ajax to do verification and signing in, so simply using MSXML2.XMLHTTP wont work.
After IE log into the site, I direct it to the page I want to save as a file, the problem is this page is returning JSON data (filename.json) - so IE is prompting to open/save/saveas rather than just opening the page, so I cant save the data of the page.
The code is below. Any help is much appreciated.
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.somesite.com"
Wait IE
With IE.Document
.getElementByID("username").value = "myusername"
.getElementByID("password").value = "mysecret"
.getElementsByName("Login")(0).Click
End With
Wait IE
'# all fine here, logged in and redirected to members page
IE.Navigate "https://www.somesite.com/api/data"
' # this link returns json data
'# this is where everything stops because Im getting a download/save as prompt in IE
EDIT: ok, I was able to get IE to display the content rather than downloading it by editing the registry to treat .json file as text files,Now the problem is the page is a json file, not a HTML file, so I cant get it's content by calling IE.Document.Body.InnerHTML like normal HTML pages.
How would I get the content of the page and assign it to a variable so I can process it?
oh, I just put this in my code:
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_CLASSES_ROOT\.json\Content Type", "text/plain", "REG_SZ
That way the file is treated as a textfile within IE and it will just open in the page. Then I can use the normal objIE.Document.Body.InnerText to get the json contents. Then I pass that variable onto my function that decodes it all.
Hope this helps someone, because all the results on google I found did not help me. Only reason I posting on this old thread!
Cheers,
Ross

Lotus Domino Designer: AJAX or some other way to open a URL to retrieve a data

Following Lotus Domino Designer: Add a button in the default calendar
The link is actually a SSO link (single sign-on) which is delivered by our API to connect the user to our application.
We must execute the url http://example.com/api.asp?cas=GETUSERTOKEN&rdn=9428521&login=mike&logincnx=adminAPIHays&pwdcnx=app
which returns the time-limited SSO link http://example.com/hays/array.asp?key=750EA68A476C9F8D26F9704B203205FDF64D2B849B688F169B398D217FFF570F54C1CB6B4635A494E504E624EDF3266D0D5C2A1210AA43EE3CD2098AE8B42DBF which connects the user.
By what means I can program this in Domino Designer?
If necessary we can put the button in a new something (not necessarily in the default calendar in fact).
Because you want to obtain another URL from an initial URL request, you will need to use a java agent to open a URL connection, and process the response to determine. The best approach is to use the J2SE URLConnection class. Once you're in a java agent, you can capture responses and store them in Documents.
If you need to do something in the UI after receiving the response, then you'll need to call the Java Agent from within a LotusScript function either from the view action or a form button. But if this is not required, you can also call the Java agent directly in view actions and form buttons. Java Agents have no UI output apart from the Java Debug Console. In Domino circles, Bob Balaban is a guru and has recently started to revise his Java in Domino writings. It provides a good insight into how it "hangs together" with the Domino API.
There are numerous examples scattered across the internet about using Java in Domino. IBM has published information on Java Agents in Domino. Some good examples can be found here, here, and here. The latest version of Domino Designer runs under Eclipse, so this may be of help to.
I did this in LotusScript:
Sub Click(Source As Button)
Dim objHttp As Variant
Dim url As String
Dim response As String
Set objHttp = CreateObject("Microsoft.XMLHTTP")
url = "http://foo.com/api.asp?cas=GETUSERTOKEN&rdn=9428521&login=mike&logincnx=adminAPIHays&pwdcnx=app"
objHttp.open "GET", url, False
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.send
newUrl = objHttp.responseText
Set w = New NotesUIWorkspace
w.UrlOpen newUrl
End Sub

What default credential Directory Entry binds to if it is running as a service on Windows

If I bind to a DirectoryEntry ( without any arguments) on the application mode to search all the users at my current domain, I could see the logged in in user is the default credential for DirectoryEntry since it finds all the users for my domain. With that, I would expect that this won't work if the application is run at service mode since account for service is SYSTEM which is not a user of my domain. However the code still works and it could get all the users of my logged in user domain.
I did some search on internet, I didn't find any answer on this when running as a service. Any idea? Any way I could get that default credential at power shell?
At service mode, the default credential for directory entry would be the credential which computer is used to login into the domain (called computer login). See this link: https://serverfault.com/questions/61191/what-happens-when-a-computer-joins-an-active-directory-domain.
I first tried to use System.Net.CredentialCache::DefaultNetworkCredentials
to try to get the default credential, however I found out the user and domain are all blank. It is confirmed from MSDN that we could not view those info with the returned NetworkCredentials.
So I added the following vb script (got the base code from this link: http://blogs.technet.com/b/heyscriptingguy/archive/2008/05/12/how-can-i-determine-the-distinguished-name-of-the-ou-where-the-logged-on-user-s-user-account-resides.aspx) to be called from power shell to get the dn of the current user
and save it to a file.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserName = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserName)
Wscript.Echo objUser.distinguishedName
Set objFS = CreateObject("Scripting.FileSystemObject")
strTemp = "c:\temp\dn.txt"
Set objOutFile = objFS.CreateTextFile(strTemp,True)
objOutFile.Write(objUser.distinguishedName)
objOutFile.Close
Then when I ran it in service context, I found out that user is my computer itself, like this:
CN=my computer name,OU=Domain computer accounts,DC=domain,DC=local

Resources