Dealing with the Web - Requesting Pages
The following code is asking Google for a search on two words: "dyalog" and "apl":
System∆Net∆WebRequest;⎕ML;⎕IO;htmlPage;MyWebRequest;TheResponse;MyStream;URL ⍝ Version 1.1 from 2007-01-05 ⋄ Kai Jaeger ⋄ APL Team Ltd ⎕ML ⎕IO←1 ⎕USING←'System,System.dll' '' URL←'http://www.google.co.uk/search?q=dyalog+apl' ⍝ Create a request for the URL MyWebRequest←System.Net.WebRequest.Create⊂URL ⍝ If required by the server,set the credentials. MyWebRequest.Credentials←System.Net.CredentialCache.DefaultCredentials ⍝ Get the response TheResponse←MyWebRequest.GetResponse ⍝ Display the status ⎕←TheResponse.StatusDescription ⍝ Get the stream containing content returned by the server MyStream←TheResponse.GetResponseStream ⍝ Open the stream using a StreamReader htmlPage←⎕TC[2]~⍨(System.IO.StreamReader.New MyStream).ReadToEnd ⍝ Reformat because we can't see much otherwise htmlPage({⍺⊂⍨⍵=⍺})←'<' ⍝ Display what we get ⎕ED'htmlPage' ⍝ End
Author: KaiJaeger
CategoryDotNet - CategoryDyalogDotNet - CategoryDyalogExamplesDotNet