It is a simple program that opens a web site in a web service written in VB .NET.
It works fine when I test it in Visual Studio, but after applying it to IIS, I can't open the Web Page.
cmd.Parameters.Add(ParamRet)
cmd.CommandText = "[dbo].[usp_ins_inq_log]"
cmd.ExecuteNonQuery()
Dim ReturnVal As Int32 = cmd.Parameters("#P_OutId").Value
conn.Close()
sUrl = sUrl + "?Id=" + ReturnVal.ToString()
Process.Start("chrome.exe", sUrl)
Related
I recently updated my application to use oauth for a swagger interface, which requires opening a webpage to a specific URL and getting the user to authorize access. I then listen for the response sent to the local host and process the access token, etc. To do this I just call process.Start(URL)
Here is my code:
Private Sub GetAuthorizationfromWeb()
Try
' Build the authorization call
Dim URL As String = ESIAuthorizeURL & "?response_type=code" & "&redirect_uri=http://"
URL &= LocalHost & ":" & LocalPort & "&client_id=" & ClientID & "&scope=" & ScopesString
Process.Start(URL)
Dim mySocket As Socket = Nothing
Dim myStream As NetworkStream = Nothing
Dim myReader As StreamReader = Nothing
Dim myWriter As StreamWriter = Nothing
myListner.Start()
mySocket = myListner.AcceptSocket() ' Wait for response
Debug.Print("After socket listen")
myStream = New NetworkStream(mySocket)
myReader = New StreamReader(myStream)
myWriter = New StreamWriter(myStream)
myWriter.AutoFlush = True
Do
AuthStreamText &= myReader.ReadLine & "|"
If AuthStreamText.Contains("code") Then
Exit Do
End If
Loop Until myReader.EndOfStream
myWriter.Write("Login Successful!" & vbCrLf & vbCrLf & "You can close this window.")
myWriter.Close()
myReader.Close()
myStream.Close()
mySocket.Close()
myListner.Stop()
Application.DoEvents()
Catch ex As Exception
Application.DoEvents()
End Try
End Sub
All of it works fine with Firefox and to some extent Chrome when they are set as the default browser. However, when I try to launch the URL with Edge or Internet Explorer set as my default browser, it just opens a blank web page or the home page. There is no attempt to navigate to the URL set as the argument.
I tried to find another way to do this but basically process.Start seems to be the only option. I'm not going to embed a webbrowser in my code for security reasons.
Any thoughts?
I am trying to upload a file with vb code.
I checked at https://www.infobyip.com/ftptest.php with this credentials and it is working :
Host : mydomain.gr
Port : 21
Login : mylogin
Pasword : mypsw
Directory :/image/catalog
My vb code is that:
Dim fname As String = "Images\Zar-" & Path.GetFileName(LocalDT(0)("ZarImageUrl").ToString)
Dim Client As New WebClient
Client.DownloadFile(LocalDT(0)("ZarImageUrl").ToString, Server.MapPath(fname))
Client.Dispose()
Upload("ftp://www.mydomain.gr", "mylogin", "mypsw", Server.MapPath(fname))
Using Client As New WebClient
Client.Credentials = New System.Net.NetworkCredential(UserName, Password)
Client.UploadFile(ftpServer + "/image/catalog/" + New FileInfo(filename).Name, "STOR", filename)
End Using
I am getting this error : Unable to connect to the remote server
Any idea?
I have an existing web crawler (WinForms) developed using VB.NET for our SEOs which utilizes Web Requests. The application works fine on a regular website but when I try to crawl SPA sites (Single Page Applications), the application can't get a proper response.
Dim siteBody As String = String.Empty
Dim cleanedURL As String
Dim wRequest As System.Net.HttpwRequestuest
Dim wResponse As System.Net.HttpwResponse
Dim rStream As System.IO.Stream
Dim reader As System.IO.StreamReader
Try
wRequest = Nothing
wResponse = Nothing
rStream = Nothing
wRequest = HttpwRequestuest.Create(urlList(i)) 'URL is being passed
wRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
wRequest.UserAgent = "DummyValue"
wRequest.AllowAutoRedirect = False
wResponse = wRequest.GetResponse()
rStream = wResponse.GetResponseStream
reader = New System.IO.StreamReader(rStream)
siteBody = reader.ReadToEnd
reader.Close()
wResponse.Close()
Catch ex As Exception
End Try
Dim passedBody = siteBody 'EMPTY RESULT
Based on the result, we will extract data and check for links and their status codes.
I have a fully functional "app" I created in Microsoft Access that I use control my Philips Hue lights. They operate via a RESTful interface using JSON commands and it was pretty simple to create the code in VBA. I wanted to make a standalone Windows app though so I can run it on my computers that don't have Access.
I'm trying to use Visual Studio 2015 to make a universal app using VB.net but I'm having problems converting some of my code over. I was able to fix most of the glitches, but I can't get the winHttpReq commands to work. In my research, it sounds like they don't have a direct correlation in VB.net but none of the suggestions I found have worked.
Dim Result As String
Dim MyURL As String, postData As String, strQuote As String
Dim winHttpReq As Object
winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
'Create address and lamp
MyURL = "http://" & IP.Text & "/api/" & Hex.Text & "/lights/" & "1" & "/state"
postData = Code.Text
winHttpReq.Open("PUT", MyURL, False)
winHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
winHttpReq.Send(postData)
I get the error that 'CreateObject' is not declared. It may be inaccessible due to its protection level. I'm pretty new to VB.net coding but all the recommendations for alternative posting methods don't seem to work. Any suggestions would be greatly appreciated.
In VB.Net, use WebRequest:
'Create address and lamp
MyURL = "http://" & IP.Text & "/api/" & Hex.Text & "/lights/" & "1" & "/state"
Dim request As WebRequest = WebRequest.Create(MyURL)
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response,HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Clean up the streams and the response.
reader.Close()
response.Close()
i have the following code,i'm trying to send an email from my windows application but it's not working... any help ? note that i'm using vb.net and i'm not getting any errors.. i'm just not receiving any emails !
Private Sub senemail()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("jocelyne_elkhoury#inmobiles.net")
mail.To.Add("jocelyne_el_khoury#hotmail.co.uk")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
End Sub
In my experience, sending email via .net (and vb6 before it) is weird. Sometimes it should work and just doesn't, sometimes because of .net bugs and sometimes incompatibility with the smtp server. Here is some code that works on VB 2008, and it should work with 2010.
Using msg As New MailMessage(New MailAddress(fromAddress, fromName), New MailAddress(toAddress))
Try
Dim mailer As New SmtpClient
msg.BodyEncoding = System.Text.Encoding.Default
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = False
mailer.Host = mailserver
mailer.Credentials = New System.Net.NetworkCredential(username, password) ' may or may not be necessary, depending on the server
mailer.Send(msg)
Catch ex As Exception
Return ex.Message
End Try
End Using ' mailmsg
If this doesn't work, try using localhost instead of 127.0.0.1 for the mailserver.
If that doesn't work, try using your system name (the one that shows up on the network) for the mailserver.
If that doesn't work, try using an external smtp server with your own username and password (just for testing).
profit.