Differences between revisions 4 and 5
Revision 4 as of 2007-01-05 07:42:38
Size: 1124
Editor: KaiJaeger
Comment:
Revision 5 as of 2007-01-11 20:53:52
Size: 1167
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 32: Line 32:

----

CategoryDyalog | CategoryDotnet

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


CategoryDyalog | CategoryDotnet

WebInterface (last edited 2015-04-05 01:29:12 by PierreGilbert)