1
1
2
2
include std/dll.e
3
3
include std/machine.e
4
+ include std/net/url.e
4
5
include std/types.e
6
+ include euphoria/info.e
5
7
6
8
public constant
7
9
INTERNET_INVALID_PORT_NUMBER = 0,
@@ -78,10 +80,48 @@ public constant
78
80
INTERNET_SERVICE_HTTP = 3,
79
81
$
80
82
83
+ public constant
84
+ INTERNET_STATUS_RESOLVING_NAME = 10,
85
+ INTERNET_STATUS_NAME_RESOLVED = 11,
86
+ INTERNET_STATUS_CONNECTING_TO_SERVER = 20,
87
+ INTERNET_STATUS_CONNECTED_TO_SERVER = 21,
88
+ INTERNET_STATUS_SENDING_REQUEST = 30,
89
+ INTERNET_STATUS_REQUEST_SENT = 31,
90
+ INTERNET_STATUS_RECEIVING_RESPONSE = 40,
91
+ INTERNET_STATUS_RESPONSE_RECEIVED = 41,
92
+ INTERNET_STATUS_CTL_RESPONSE_RECEIVED = 42,
93
+ INTERNET_STATUS_PREFETCH = 43,
94
+ INTERNET_STATUS_CLOSING_CONNECTION = 50,
95
+ INTERNET_STATUS_CONNECTION_CLOSED = 51,
96
+ INTERNET_STATUS_HANDLE_CREATED = 60,
97
+ INTERNET_STATUS_HANDLE_CLOSING = 70,
98
+ INTERNET_STATUS_DETECTING_PROXY = 80,
99
+ INTERNET_STATUS_REQUEST_COMPLETE = 100,
100
+ INTERNET_STATUS_REDIRECT = 110,
101
+ INTERNET_STATUS_INTERMEDIATE_RESPONSE = 120,
102
+ INTERNET_STATUS_USER_INPUT_REQUIRED = 140,
103
+ INTERNET_STATUS_STATE_CHANGE = 200,
104
+ INTERNET_STATUS_COOKIE_SENT = 320,
105
+ INTERNET_STATUS_COOKIE_RECEIVED = 321,
106
+ INTERNET_STATUS_PRIVACY_IMPACTED = 324,
107
+ INTERNET_STATUS_P3P_HEADER = 325,
108
+ INTERNET_STATUS_P3P_POLICYREF = 326,
109
+ INTERNET_STATUS_COOKIE_HISTORY = 327,
110
+ $
111
+
112
+ public constant
113
+ INTERNET_STATE_CONNECTED = 0x00000001,
114
+ INTERNET_STATE_DISCONNECTED = 0x00000002,
115
+ INTERNET_STATE_DISCONNECTED_BY_USER = 0x00000010,
116
+ INTERNET_STATE_IDLE = 0x00000100,
117
+ INTERNET_STATE_BUSY = 0x00000200,
118
+ $
119
+
81
120
public constant ERROR_INSUFFICIENT_BUFFER = 122
82
121
122
+ public constant AGENT_STRING = "Euphoria/" & version_string_short()
123
+
83
124
atom Wininet = open_dll( "Wininet.dll" )
84
- ? Wininet
85
125
86
126
constant
87
127
C_DWORD_PTR = C_POINTER,
@@ -101,13 +141,6 @@ constant
101
141
xInternetReadFile = define_c_func( Wininet, "InternetReadFile", {C_HINTERNET,C_LPVOID,C_DWORD,C_LPDWORD}, C_BOOL ),
102
142
$
103
143
104
- ? xHttpOpenRequest
105
- & xHttpSendRequest
106
- & xInternetCloseHandle
107
- & xInternetConnect
108
- & xInternetOpen
109
- & xInternetReadFile
110
-
111
144
function allocate_wstring_pointer_array( object string_list, boolean cleanup = FALSE )
112
145
113
146
if atom( string_list ) then return NULL end if
@@ -194,4 +227,44 @@ public function InternetReadFile( atom hFile, atom dwNumberOfBytesToRead = 4096
194
227
return peek({ lpBuffer, dwNumberOfBytesRead })
195
228
end function
196
229
230
+ public function HttpGetRequest( sequence url, object accept_types = NULL )
231
+
232
+ atom flags = INTERNET_FLAG_NO_UI
233
+ atom port = INTERNET_DEFAULT_HTTP_PORT
234
+
235
+ sequence parsed = url:parse( url )
236
+
237
+ if equal( parsed[1], "https" ) then
238
+ flags += INTERNET_FLAG_SECURE
239
+ port = INTERNET_DEFAULT_HTTPS_PORT
240
+ end if
241
+
242
+ if not equal( parsed[3], 0 ) then
243
+ port = parsed[3]
244
+ end if
245
+
246
+ atom ih = InternetOpen( AGENT_STRING, INTERNET_OPEN_TYPE_PRECONFIG )
247
+ atom ch = InternetConnect( ih, parsed[2], port )
248
+ atom req = HttpOpenRequest( ch, "GET", parsed[4], , , accept_types, flags )
249
+
250
+ sequence buff = {}
251
+
252
+ if HttpSendRequest( req ) then
253
+
254
+ sequence data
255
+
256
+ while length( data ) with entry do
257
+ buff &= data
258
+ entry
259
+ data = InternetReadFile( req )
260
+ end while
261
+
262
+ end if
263
+
264
+ InternetCloseHandle( req )
265
+ InternetCloseHandle( ch )
266
+ InternetCloseHandle( ih )
267
+
268
+ return buff
269
+ end function
197
270
0 commit comments