[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Code to access data from website

Hi Experts.  I currently log onto a website where I collect data relating to usage of a data line.
I log on with a username and password, click a menu item and the data is presented on the web page.  All very standard stuff and the site does not have a security certificate.  I'm looking for code samples or ways to access this data automatically.   I'm thinking of an automated process of logging in with the username and password, getting to the data and then downloading it, automatically and at regular time intervals.  
0
PNRT
Asked:
PNRT
  • 2
  • 2
1 Solution
 
jet-blackCommented:
several tutorials exist on the internet. check them:
http://lmgtfy.com/?q=php+curl+login
0
 
zadeveloperCommented:
try this
static void Main(string[] args)
        {
            var request = WebRequest.Create("http://www.zadeveloper.com/");
            request.Credentials = new NetworkCredential("username", "password");
            
            var response = request.GetResponse();

            var buffer = new byte[1024];
            var htmlPage = string.Empty;

            using (var dataStream = response.GetResponseStream())
            {
                using (var reader = new StreamReader (dataStream))
                {
                    htmlPage = reader.ReadToEnd();
                }
            }
        }

Open in new window

0
 
PNRTAuthor Commented:
Damn it.  My fault entirelly, I forget to mention, would you perhaps have the VB.Net2 version.
 
0
 
zadeveloperCommented:

Sub DownloadWebPage()
Dim htmlPage As String
Dim website As String = "http://www.zadeveloper.com
Dim uid As String = "username"
Dim pwd As String = "password"
Dim fileSave As String = "c:\file.html"
Dim request As WebRequest = WebRequest.Create(website)
request.Credentials = New NetworkCredential(uid, pwd)
Dim dataStream As Stream = request.GetResponse.GetResponseStream()
Dim reader As StreamReader = New StreamReader(dataStream)
htmlPage = reader.ReadToEnd
reader.Close()
reader.Dispose()
Dim fs As FileStream = New FileStream(fileSave, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)
Dim writer As StreamWriter = New StreamWriter(fs)
writer.Write(htmlPage)
writer.Close()
fs.Close()
End Sub
0
 
PNRTAuthor Commented:
A very helpful expert.   Thank you
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now