XMLHTTP-Request (AJAX) with VBSkript does not work with proxy connection - ajax

I'm using a XMLHTTP-Request to get data from a website to work with them in VBS. This works great with a default internet connection. But currently I've to deal with a customer, which uses a "proxy" connection.
Unfortunately I'm not very familiar to different proxy-solutions. The behavior is: I'm opening the browser and I'll get a authorisation dialog (username/password). After entering username/password it can be accessed to all websites. If I close the browser and start it again, the autorisation dialog appears again.
Here a little bit of code. I'm working with a "better notepad", so I can't see other object properties:
Set XMLHTTP = CreateObject("Microsoft.XMLHTTP")
XMLHTTP.Open "GET", "http://www.mywebsite.de/getData.php" ,0
XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHTTP.Send("content=1")
MsgBox(XMLHTTP.responseText)
If I execute this code on the machine with the forced proxy, I'll get a "access denied" error immediately.
How can I add proxy authorisation support here? If indeed such a thing is possible ...
Thank you!

I've found the solution: I have to change the class, because Microsoft.XMLHTTP does not support proxy configurations:
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.4.0")
xmlhttp.Open "POST","http://www.yourwebsite.com",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setProxy 2, "192.168.0.222:8080"
xmlhttp.setProxyCredentials "your_username" , "password_for_username"
xmlhttp.send
MsgBox(xmlhttp.responseText)
Notice some important details:
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.4.0")
setProxy and setProxyCredentials methods requires version number:
It's important to use a version number at the end of the parameter. If I don't use a version number, it will look for an old version of the class without the setProyx and setProxyCredentials methods. An error message appears ("object does not have the method ...").
Version number isn't trivial:
But the version number itself isn't trivial as well. In my local enviroment (W7x64) I'll have to take version number "4.0", but at my client's server it doesn't work ("could not create an object ..."). I'll have to take version number "6.0". If you're not sure, which version is installed, you can look it up in the registry, just search for "MSXML2.ServerXMLHTTP". In my case there are various keys with the right version number:

Related

Xamarin.Auth - Google authentication won't open in browser

I'm trying to do authentication on my Android application using Xamarin.Auth. Some time ago, Google made the policy that you cannot do this in an embedded web view (for totally valid reasons).
I'm trying to open the account authentication page in a browser, but keep getting the embedded web view. I understand that isUsingNativeUI needs to be true in the following code:
_auth = new OAuth2Authenticator(clientId, string.Empty, scope,
new Uri(Constant.AuthorizeUrl),
new Uri(redirectUrl),
new Uri(Constant.AccessTokenUrl),
null,
isUsingNativeUI = true);
At every point in my application, this always equals true.
Elsewhere, I have code that redirects to what should be a browser:
var authenticator = Auth.GetAuthenticator();
Intent intent = authenticator.GetUI(this);
this.StartActivity(intent);
Regardless, I keep getting a dreaded 403 disallowed_useragent error whenever I try to run the project. Is there another element to this that I'm missing?
To my knowledge, setting auth.IsUsingNativeUI = true in the constructor should dictate that it must open in a browser. I've been following this example to try and debug with no success. I even pulled the guy's repo down to my machine and ran it - the Intent variable at the moment of redirection is almost identical.
Could there be something stupid that I'm missing? What else might be going wrong?
I realize this is an old question, but I had the same issue.
You have to install version 1.5.0.3 of the Xamarin.Auth Nuget package. The newest one (version 1.7.0 right now) doesn't work. You'll have to also install the PCLCrypto nuget package in order to get that version to work.

Gmail Gadget Error 406 being thrown on osapi.http.post

We have multiple marketplace Apps that use Gmail Contextual Gadgets. These have been running for years successfully.
We are now noticing the following intermittent error being thrown when calling out to an external web server using open social osapi.http.post
"{"id":"http.post","error":{"message":"Response not valid JSON","code":406}}"
We have checked and there is nothing wrong with our server. We can make the call directly to our server successfully without fail.
We can replicate the issue calling to multiple servers running different apps/gadgets. The only commonality appears to be the use of osapi.http.post.
Here is the post
osapi.http.post({
'body': postdata,
'href': serverUrl + 'iLinkStreamer.ashx?data=' + "" + setTimeStamp() + debugString,
'format': 'json',
'authz': 'signed',
'noCache': true
}).execute(displayStreamList);
which raises the 406 error as above
Has anybody else noticed this issue?? Not sure how we can address it?
I had the same issue for a while and finally found the problem. I was also invoking external resources using osapi.http.post. I read the new documentation and found that there is a new way to do the same.
Check this url for more details, but the idea is that now you'll need to use makeRequest API, it will look something like this:
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
gadgets.io.makeRequest("https://your.backend.com", on_response_function, params);
...
def on_response_function(response){ ... }
I hope this helps someone.
I'm not sure if I'm the only one, but I never received a notification message that the previous API will be deprecated. :(

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

VB6: Automation error The remote procedure call failed

In my VB6 application sometimes in some customer PC we get error like
Automation error
The remote procedure call failed.
The error comes for the code shown below
Dim WithEvents Web_popup As SHDocVw.InternetExplorer
Set Web_popup = Nothing
Set Web_popup = New SHDocVw.InternetExplorer
Set ppDisp = Web_popup.Application
Also for the below code
Dim iE As New SHDocVw.InternetExplorer iE.Navigate "www.example.com", 4 + 8
iE.Visible = True
What may be the reason for these errors? How to solve it?
You should include more information when asking for help. More importantly, you should point exactly which lines are causing the error. That being said, it sounds to me that you are not checking the ready state of the download of html to Explorer. Interacting with a web page before the web page has been completely download will cause this symptom.
If you are checking the ready state, the only other way I was able to produce the error was turning on protected mode in Internet Explorer. Some websites cause the error when Protected mode is on.

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

Resources