i want to conver some my custom function for classic asp to a dll file by vb 6 - asp-classic

this is my classic asp function :
Private Function XMLHttpRequest(XmlHttpMode, XmlHttpURL, XmlHttpData)
Dim MyXmlhttp
Set MyXmlhttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1") '
With MyXmlhttp
.setTimeouts 6000000, 600000, 600000, 600000 '
.Open "GET", XmlHttpURL, True
.Option(4) = 13056 '
.Option(6) = True '
.SetRequestHeader "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
.send (XmlHttpData)
.waitForResponse (2000)
If MyXmlhttp.Status = 200 Then
XMLHttpRequest = .ResponseBody
Else
XMLHttpRequest = "error code:" & .Status
End If
End With
Set MyXmlhttp = Nothing
End Function
in iis run very good,but i convert to dll by vb6 ,then give me a error tip:
“Object does not support this property or method“
VB6 source code Reference libary below,i want to know what object wo i need include my vb code project (for make dll file,then i can call in my classi asp source code).thanks in advance!

If you are using Microsoft WinHTTP Services as your screenshot shows, declare your variable as WinHttpRequest instead of XMLHttpRequest. Everything should work the same as with the XMLHttpRequest object.

Related

I am loging into the following website via splash lua script but can't logg in

I want to log in into the https://login.starcitygames.com/ website by using splash integration with lua script. i first check in locallhost for testing them.
when detecting all the form css tags and entering log in credentials i failed to logged in.
The code are here:
function main(splash)
splash:set_custom_headers({
["user-agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36",
})
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(10))
splash:set_viewport_full()
local search_input = splash:select('input[type=text]')
search_input:send_text("(censored)#gmail.com")
local search_input = splash:select('input[name=password]')
search_input:send_text("(censored)")
assert(splash:wait(5))
local submit_button = splash:select('button[type=submit]')
submit_button:click()
assert(splash:wait(15))
return {
html = splash:html(),
png = splash.png(),
}
end
After when i run it on localhost 'http://0.0.0.0:8050/' then the following results is come and can't logged in .
May be the css tags i use is incorrect or anything .
I am new to splash lua so don't understand it.
the output is:
Try to replace local search_input = splash:select('input[type=text]') with local search_input = splash:select('input[name=username]').

How to get a response cookie with flurl

How to get a response cookie with flurl? I've searched for some references and studied on flurl.dev but still confused how to apply them. sorry I am not a programmer, I still have a lot to learn.
Simple code that i use :
var strUrl = await url
.WithHeaders(new
{
user_agent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
content_type = "application/json",
cookie = "cookie"
})
.PostJsonAsync(new
{
user = "user",
password = "password"
})
.ReceiveString();
Result : 200 OK
The problem here is that when you call ReceiveString(), you're getting the response body and effectively discarding the other aspects of the response message returned by PostJsonAsync. You can get the response, cookies, and body in separate steps like this:
var resp = await url
.WithHeaders(...)
.PostJsonAsync(...);
var cookies = resp.Cookies; // list of FlurlCookie objects
var body = await resp.GetStringAsync();

ASP.NET login using VBA via ServerXMLHTTP - new sign in notification and security que stion

I have VBA code which allows me to successfully submit my login credentials via POST method. Unfortunately the website uses security questions whenever a different login pattern is detected and the question appears in POST request response text, also I receive email notification about new sign in. I had the security questions before, while using manual logins, after logging through different browser or clearing cache.
I guessed that cookies could be the solution, but when I used:
.sendRequestHeader "Cookie", myCookieString
with the same cookie string which is sent via manual login POST request, I also received 200 status response. What can I do to login directly, so that no security questions are asked?
Also, are "Cache-Control", "Pragma" and "User-Agent" RequestHeaders any use in my code?
Option Explicit
Sub GuruLogin()
Dim viewStateGen As String, viewState As String
Dim htmlDoc As New HTMLDocument
Dim allParams As Variant 'string generates invalid parameter error
Dim serverXMLHTTP As Object 'XMLHTTP causes access denied error on .send
Set serverXMLHTTP = CreateObject("MSXML2.serverXMLHTTP")
With serverXMLHTTP
.Open "GET", "https://www.guru.com/login.aspx", False
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"
.send
htmlDoc.body.innerHTML = .responseText
With htmlDoc
viewStateGen = .getElementById("__VIEWSTATEGENERATOR").Value
viewState = EncodeURL(.getElementById("__VIEWSTATE").Value)
End With
End With
With serverXMLHTTP
.Open "POST", "https://www.guru.com/login.aspx", False
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"
allParams = "ctl00_scriptMgr_HiddenField=&__LASTFOCUS=&__EVENTTARGET=&__EVENTARGUMENT=&" & _
"__VIEWSTATE=" & viewState & "&__VIEWSTATEGENERATOR=" & viewStateGen & "&ctl00%24scriptMgr=&" & _
"ctl00%24ContentPlaceHolder1%24ucLogin%24txtUserName%24txtUserName_TextBox=mygmailname%40gmail.com&" & _
"ctl00%24ContentPlaceHolder1%24ucLogin%24txtPassword%24txtPassword_TextBox=mygurupassword&" & _
"ctl00%24ContentPlaceHolder1%24btnLoginAccount%24btnLoginAccount_Button=Sign+In&" & _
"ctl00%24ContentPlaceHolder1%24hdnLinkedInClntID=77aj4w1f86tc9b&" & _
"ctl00%24ContentPlaceHolder1%24hdnGooglePlusClntID=130090623010-1785qcncrqfi1uv1ge0btt8nspiv2spj.apps.googleusercontent.com&" & _
"ctl00%24ContentPlaceHolder1%24hdnFacebookClntID=797387497025842&" & _
"ctl00%24hdnGuid=GUID"
.send allParams
If .Status <> 302 Then Debug.Print "login error, status " & .Status '302 = redirect (success), 200 = login error
End With
End Sub
Function used to properly encode viewState string:
Public Function EncodeURL(inputURL As String) As String 'in Excel 2013+ there is WorksheetFunction.EncodeUrl(InputString)
Static EncoderScriptEngine As Object
If EncoderScriptEngine Is Nothing Then Set EncoderScriptEngine = CreateObject("ScriptControl")
With EncoderScriptEngine
.Language = "JScript"
EncodeURL = .Run("encodeURIComponent", inputURL)
End With
End Function
I have solved this issue, it was quite trivial.
I followed the advice in similar threads and installed a free tool called Telerik Fiddler to troubleshoot requests. To make my requests from macros be visible for this program, I had to use this line:
WinHttp.setProxy 2, "127.0.0.1:8888" 'make the request be detected by Fiddler
If you want to see requests from Firefox or avoid https site security alerts when Fiddler is on, follow great tutorials on developer's website.
By comparing manual login requests and automated ones, my obvious mistake has shown:
Security answer page was the result of POST redirecting me to the main page automatically, what means without response cookie. Lack of this cookie caused the next redirect - to security question page. I'll need to disable auto redirects, get the response cookie from POST and send GET request to the main page.

POST data into ASPX with requests. How to fix "remote mashine error" message

I'm trying to scrap data from aspx page using request with POST data.
On parsed html I'm getting an error "An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine."
I was searching for solutions a while but frankly I'm new in Python and can't really figure out what's wrong.
The ASPX has javaonclick function which opens a new window with data in html.
The code I've created is below.
Any help or suggestions would be greatly welcomed. Thank you!
import requests
from bs4 import BeautifulSoup
session = requests.Session()
url = 'http://ws1.osfi-bsif.gc.ca/WebApps/FINDAT/Insurance.aspx?T=0&LANG=E'
r=session.get(url)
soup = BeautifulSoup(r.content,'lxml')
viewstate = soup.select("#__VIEWSTATE")[0]['value']
eventvalidation = soup.select("#__EVENTVALIDATION")[0]['value']
payload = {
r'__EVENTTARGET': r'',
r'__EVENTARGUMENT': r'',
r'__LASTFOCUS': r'',
r'__VIEWSTATE': viewstate,
r'__VIEWSTATEGENERATOR': r'B2E4460D',
r'__EVENTVALIDATION': eventvalidation,
r'InsuranceWebPartManager$gwpinsuranceControl$insuranceControl$institutionType': r'radioButton1',
r'InsuranceWebPartManager$gwpinsuranceControl$insuranceControl$institutionDropDownList': r'F018',
r'InsuranceWebPartManager$gwpinsuranceControl$insuranceControl$reportTemplateDropDownList': r'C_LIFE-1',
r'InsuranceWebPartManager$gwpinsuranceControl$insuranceControl$reportDateDropDownList': r'3+-+2015',
r'InsuranceWebPartManager$gwpinsuranceControl$insuranceControl$submitButton': r'Submit'
}
HEADER = {
"Content-Type":"application/x-www-form-urlencoded",
"Content-Length":"11759",
"Host":"ws1.osfi-bsif.gc.ca",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language":"en-US,en;q=0.5",
"Cache-Control": "max-age=0",
"Accept-Encoding":"gzip, deflate",
"Connection":"keep-alive",
}
df = session.post(url, data=payload, headers=HEADER)
print df.text

IIS 7.5 response does not contain setCookie when User-Agent = CasperJS

HTTP header sent by CasperJS contains:
...
- User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) CasperJS/1.0.2+Phantomjs/1.8.2 Safari/534.34
...
Response does not contain SetCookie value!
When I change user agent manually:
PageSettings: {
userAgent: "User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"
}
All works fine. I'm using ASP.Net MVC.
How fix It on server side?
This is probably because the runtime determines your browser capabilities based on the user agent header. Try to turn it off like this (or similarily) to try if it helps:
// Global.asax.cs
void Application_OnBeginRequest( object sender, EventArgs e )
{
HttpApplication app = ( HttpApplication )sender;
HttpContext ctx = app.Context;
...
if (
ctx.Request != null &&
!string.IsNullOrEmpty( ctx.Request.UserAgent ) &&
ctx.Request.UserAgent.Contains( "CasperJS" )
)
ctx.Request.Browser.Adapters.Clear();
..
}
The snippet above is not necessarily a good idea - it totally removes the rendering adapter (which may possibly not be good!) for some browsers but it should be a good starting point for something more fancy.
I hope this helps, we were able to resolve some rendering issues with the snippet and I hope it also helps with the cookie issue.
I found a solve here: https://stackoverflow.com/a/4816391/1010404
I put generic.browser into App_Browsers folder.
File contains:
<browsers>
<browser refID="Default">
<capabilities>
<capability name="cookies" value="true" />
</capabilities>
</browser>
</browsers>
And all work fine.

Resources