After clicking a button in ASPX page I have to execute a URL
http://127.0.0.1/phptest/sendmail.php?id=+#USERNAME
using VB.net. #USERNAME comes from textbox.
Make an HTTP request if you need to call a URL from VBScript:
username = ...
url = "http://127.0.0.1/phptest/sendmail.php?id=+#" & username
Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "GET", url, False
req.send
If req.status = 200 Then
'request successful
Else
'request failed
End If
Try something like that in vbscript :
Dim URL,ws,USERNAME
USERNAME = InputBox("Type your USERNAME","USERNAME","USERNAME")
URL = "http://127.0.0.1/phptest/sendmail.php?id=+#"& USERNAME &""
set ws = CreateObject("wscript.shell")
ws.run URL
Related
I am trying to download a file that is behind a login page. I have looked into many ways to add credentials but the response is always the log in page's html. I have tried 2 passes with client.uploadValues or client.uploadstring to get a cookie and a single pass just providing credentials.
Public Sub downloadImage()
Dim username As String = "xxxxx"
Dim password As String = "xxxxx"
Using client As New WebClient()
client.Credentials = New NetworkCredential(username, password)
client.DownloadFile("https://retailerservices.domain.com/Image/ItemHighRes/26634/1", AppDomain.CurrentDomain.BaseDirectory & "test.jpg")
End Using
End Sub
Any recommendations?
I am trying to call an asp page with request parameters from an asp in my application. Both asp pages reside on the same server. I tried this with MSXML2.ServerXMLHTTP but it did not work. Some code is below
Function URLGet(URL)
Set Http = CreateObject("MSXML2.ServerXMLHTTP")
Http.Open "GET",URL,True
Http.Send
pagestatus = Http.status
if pagestatus<>"200" then
URLGet="Error:"& pagestatus
else
' URLGet = Http.ResponseBody
URLGet = Http.responseText
end if
End Function
In this URL comes as below
/getchart.asp?Met=node1&SubMet=3232
Please tell me where I am wrong
I try to use basic authentication in VB.NET side to login Pentaho
I use the default account of Pentaho for testing
username: joe
password: password
I have following code in VB.NET for basic authentication to Pentaho
Dim request = WebRequest.Create("http://x.x.x.x:8080/pentaho/Home")
Dim authInfo As String = Convert.ToString(userName) & ":" & Convert.ToString(userPassword)
authInfo = Convert.ToBase64String(Encoding.[Default].GetBytes(authInfo))
request.Headers("Authorization") = "Basic " & authInfo
Dim response As WebResponse = request.GetResponse()
After ran the request.GetResponse() can get the successful result. So I think the Pentaho login and authentication successfully
But when I go to http://x.x.x.x:8080/pentaho/Home Pentaho still prompt to Login Pageā¦
Do You know What wrong of my code?
Thanks in advance!!
Not sure what you're trying to do here. Where are you going to pentaho/Home. In your code ?
If you want to programatically call a certain URL in Pentaho, it's probably easier to append the credentials to the query string.
You can use Basic Authentication method, I already answered this question in bellow post.
enter link description here
Eg-
WebClient webClient = new System.Net.WebClient();
Uri uri = new Uri("http://serverDomain:8080/pentaho/Home");
//Give user name and password here
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("username:password");
var encodedString = System.Convert.ToBase64String(plainTextBytes);
webClient.Headers["Authorization"] = "Basic " + encodedString;
webClient.Encoding = Encoding.UTF8;
App.WindowManager.ConsoleWrite(uri.ToString());
webClient.UploadStringAsync(uri, "POST", "");
I am building a sister site. I want my logged in user to be able to login to the sister site.
The user is entered into both databases and has a token (guid) that matches.
I am posting the token in a token-auth page via httpwebrequest to the sister site.
The sister sites locates the user from the database with the matching token.
(so far so good)
The token-auth page (via httpwebrequest) is supposed to set a cookie that my forms authentication checks. (Then the page does a redirect to the sister site and user should be logged in.)
The problem is the last part. The cookie is not being set by the token-auth page via httpwebrequest.
Thus, forms authentication fails and the user login appears.
I see the cookie from the httpwebrequest via the CookieContainer; however it's not being saved to the cookies on the computer... and then the authentication on the redirect fails.
Anyone know how to get the cookies to save via httpwebrequest? This should be possible right?
Here's some code:
The HttpWebRequest page (on load)
Dim baseURL As String = "http://localhost:5894"
Dim poststring As String = String.Format("token={0}", u.toolkit_token)
Dim url As String = baseURL & "/GetAuthToken.aspx"
Dim cookies As CookieContainer = New CookieContainer()
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
req.Accept = "*/*"
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.AllowAutoRedirect = False
req.CookieContainer = cookies
Dim bytedata() As Byte = Encoding.UTF8.GetBytes(poststring)
req.ContentLength = bytedata.Length
Dim rs As Stream = req.GetRequestStream()
rs.Write(bytedata, 0, bytedata.Length)
rs.Close()
Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim sr As Stream = res.GetResponseStream()
Dim result As String = String.Empty
Dim reader As New StreamReader(sr)
result = reader.ReadToEnd
If result = "200" Then
Response.Redirect(baseURL)
Else
Response.Write("Error: Token Not Authorized.")
End If
The Auth-Token page
If Not Request.Form("token") Is Nothing Then
Dim u As BusinessLayer.DataContainer.oUser = Nothing
u = BusinessLayer.BusinessObject.GetUserByToken(Request.Form("token"))
If u IsNot Nothing Then
'-----Set Cookie
Dim cookie As HttpCookie = Nothing
Dim _CookieId As String = Guid.NewGuid().ToString() & "-" & Guid.NewGuid().ToString()
Call BusinessLayer.BusinessObject.UpdateUsersCookieId(_CookieId, u.id)
cookie = New HttpCookie("KeepSignedIn")
cookie.Values.Add("KeepSignedIn", "True")
cookie.Values.Remove("CookieId")
cookie.Values.Add("CookieId", _CookieId)
cookie.Expires = Now.AddYears(1)
Response.Cookies.Add(cookie)
'---------------
Response.Write("200")
End If
End If
Please advise on how to get the Auth-Token page to save it's cookies to the file system.
Is it a cross-domain issue? How else would you go about this?
I should also note that if I login from the site directly, not using the token page, the forms authentication works using the cookie. I've used this code for years. I'm certain it is not an issue with that. The cookie is just not there to authentication against when using the token-auth page.
I am working on Classic ASP and was going through a possible solution of posting and reading an xml.
I read Tim's reply (which is pasted below) but this doesn't work for me. It seems xmlDoc.load(Request) doesn't load anything. What could be wrong here? I would very much appreciate a prompt response.
This is the posting page:
url = "www.receivingwebsite.com\asp\receivingwebpage.asp"
information = "<Send><UserName>Colt</UserName><PassWord>Taylor</PassWord><Data>100</Data></Send>"
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send information
This is the receiving page:
Dim xmlDoc
Dim userName
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(Request)
userName = xmlDoc.documentElement.selectSingleNode("UserName").firstChild.nodeValue
Try this :
Dim objXmlRequest
Set objXmlRequest = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")
objXmlRequest.async = False
objXmlRequest.setProperty "ServerHTTPRequest", True
objXmlRequest.validateOnParse = True
objXmlRequest.preserveWhiteSpace = False
IF objXmlRequest.Load (Request) THEN
''' GET THE REQUEST FROM CLIENT
strQuery = "//" & "ActionName"
Set oNode = objXmlRequest.selectSingleNode(strQuery)
strActionName = oNode.Text
END IF
' The key is in the property set ... check ".setProperty "ServerHTTPRequest", True"
Bye, Martin.