-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinHttp.au3
2043 lines (1993 loc) · 112 KB
/
WinHttp.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include-once
#include "WinHttpConstants.au3"
; #INDEX# ===================================================================================
; Title ...............: WinHttp
; File Name............: WinHttp.au3
; File Version.........: 1.6.2.5
; Min. AutoIt Version..: v3.3.2.0
; Description .........: AutoIt wrapper for WinHttp functions
; Author... ...........: trancexx, ProgAndy
; Dll .................: winhttp.dll, kernel32.dll
; ===========================================================================================
; #CONSTANTS# ===============================================================================
Global Const $hWINHTTPDLL__WINHTTP = DllOpen("winhttp.dll")
DllOpen("winhttp.dll") ; making sure reference count never reaches 0
;============================================================================================
; #CURRENT# =================================================================================
;_WinHttpAddRequestHeaders
;_WinHttpBinaryConcat
;_WinHttpCheckPlatform
;_WinHttpCloseHandle
;_WinHttpConnect
;_WinHttpCrackUrl
;_WinHttpCreateUrl
;_WinHttpDetectAutoProxyConfigUrl
;_WinHttpGetDefaultProxyConfiguration
;_WinHttpGetIEProxyConfigForCurrentUser
;_WinHttpOpen
;_WinHttpOpenRequest
;_WinHttpQueryDataAvailable
;_WinHttpQueryHeaders
;_WinHttpQueryOption
;_WinHttpReadData
;_WinHttpReceiveResponse
;_WinHttpSendRequest
;_WinHttpSetCredentials
;_WinHttpSetDefaultProxyConfiguration
;_WinHttpSetOption
;_WinHttpSetStatusCallback
;_WinHttpSetTimeouts
;_WinHttpSimpleFormFill
;_WinHttpSimpleReadData
;_WinHttpSimpleReadDataAsync
;_WinHttpSimpleRequest
;_WinHttpSimpleSendRequest
;_WinHttpSimpleSendSSLRequest
;_WinHttpSimpleSSLRequest
;_WinHttpTimeFromSystemTime
;_WinHttpTimeToSystemTime
;_WinHttpWriteData
; ===========================================================================================
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpAddRequestHeaders
; Description ...: Adds one or more HTTP request headers to the HTTP request handle.
; Syntax.........: _WinHttpAddRequestHeaders ($hRequest, $sHeaders [, $iModifiers = Default ])
; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest function.
; $sHeader - [optional] Header(s) to append to the request.
; $iModifier - [optional] Contains the flags used to modify the semantics of this function. Default is $WINHTTP_ADDREQ_FLAG_ADD_IF_NEW.
; Return values .: Success - Returns 1
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: In case of multiple additions at once, must use @CRLF to separate each $hRequest and responded $sHeaders and $iModifiers.
; Related .......: _WinHttpOpenRequest, _WinHttpQueryHeaders
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384087(VS.85).aspx
; Example .......: 3456
;============================================================================================
Func _WinHttpAddRequestHeaders($hRequest, $sHeader, $iModifier = Default)
__WinHttpDefault($iModifier, $WINHTTP_ADDREQ_FLAG_ADD_IF_NEW)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpAddRequestHeaders", _
"handle", $hRequest, _
"wstr", $sHeader, _
"dword", -1, _
"dword", $iModifier)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpAddRequestHeaders
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpBinaryConcat
; Description ...: Concatenates two binary data returned by _WinHttpReadData() in binary mode.
; Syntax.........: _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
; Parameters ....: $bBinary1 - Binary data that is to be concatenated.
; $bBinary2 - Binary data to concatenate.
; Return values .: Success - Returns concatenated binary data.
; Failure - Returns empty binary and sets @error:
; |1 - Invalid input.
; Author ........: ProgAndy
; Modified.......: trancexx
; Remarks .......:
; Related .......: _WinHttpReadData
; Link ..........:
; Example .......:
;============================================================================================
Func _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
Switch IsBinary($bBinary1) + 2 * IsBinary($bBinary2)
Case 0
Return SetError(1, 0, Binary(''))
Case 1
Return $bBinary1
Case 2
Return $bBinary2
EndSwitch
Local $tAuxiliary = DllStructCreate("byte[" & BinaryLen($bBinary1) & "];byte[" & BinaryLen($bBinary2) & "]")
DllStructSetData($tAuxiliary, 1, $bBinary1)
DllStructSetData($tAuxiliary, 2, $bBinary2)
Local $tOutput = DllStructCreate("byte[" & DllStructGetSize($tAuxiliary) & "]", DllStructGetPtr($tAuxiliary))
Return DllStructGetData($tOutput, 1)
EndFunc ;==>_WinHttpBinaryConcat
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpCheckPlatform
; Description ...: Determines whether the current platform is supported by this version of Microsoft Windows HTTP Services (WinHTTP).
; Syntax.........: _WinHttpCheckPlatform()
; Parameters ....: None
; Return values .: Success - Returns 1 if current platform is supported
; - Returns 0 if current platform is not supported
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384089(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpCheckPlatform()
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCheckPlatform")
If @error Then Return SetError(1, 0, 0)
Return $aCall[0]
EndFunc ;==>_WinHttpCheckPlatform
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpCloseHandle
; Description ...: Closes a single handle.
; Syntax.........: _WinHttpCloseHandle($hInternet)
; Parameters ....: $hInternet - Valid handle to be closed.
; Return values .: Success - Returns 1
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpConnect, _WinHttpOpen, _WinHttpOpenRequest
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384090(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpCloseHandle($hInternet)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCloseHandle", "handle", $hInternet)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpCloseHandle
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpConnect
; Description ...: Specifies the initial target server of an HTTP request and returns connection handle to an HTTP session for that initial target.
; Syntax.........: _WinHttpConnect($hSession, $sServerName [, $iServerPort = Default ])
; Parameters ....: $hSession - Valid WinHttp session handle returned by a previous call to WinHttpOpen.
; $sServerName - Host name of an HTTP server.
; $iServerPort - [optional] TCP/IP port on the server to which a connection is made (default is $INTERNET_DEFAULT_PORT)
; Return values .: Success - Returns a valid connection handle to the HTTP session
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: $iServerPort can be defined via global constants $INTERNET_DEFAULT_PORT, $INTERNET_DEFAULT_HTTP_PORT or $INTERNET_DEFAULT_HTTPS_PORT
; Related .......: _WinHttpOpen
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384091(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpConnect($hSession, $sServerName, $iServerPort = Default)
__WinHttpDefault($iServerPort, $INTERNET_DEFAULT_PORT)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpConnect", _
"handle", $hSession, _
"wstr", $sServerName, _
"dword", $iServerPort, _
"dword", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return $aCall[0]
EndFunc ;==>_WinHttpConnect
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpCrackUrl
; Description ...: Separates a URL into its component parts such as host name and path.
; Syntax.........: _WinHttpCrackUrl($sURL [, $iFlag = Default ])
; Parameters ....: $sURL - String. Canonical URL to separate.
; $iFlag - [optional] Flag that control the operation. Default is $ICU_ESCAPE
; Return values .: Success - Returns array with 8 elements:
; |$array[0] - is scheme name
; |$array[1] - is internet protocol scheme
; |$array[2] - is host name
; |$array[3] - is port number
; |$array[4] - is user name
; |$array[5] - is password
; |$array[6] - is URL path
; |$array[7] - is extra information
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: ProgAndy
; Modified.......: trancexx
; Remarks .......: $iFlag is defined in WinHttpConstants.au3 and can be:
; |$ICU_DECODE - Converts characters that are "escape encoded" (%xx) to their non-escaped form.
; |$ICU_ESCAPE - Escapes certain characters to their escape sequences (%xx).
; Related .......: _WinHttpCreateUrl
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384092(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpCrackUrl($sURL, $iFlag = Default)
__WinHttpDefault($iFlag, $ICU_ESCAPE)
Local $tURL_COMPONENTS = DllStructCreate("dword StructSize;" & _
"ptr SchemeName;" & _
"dword SchemeNameLength;" & _
"int Scheme;" & _
"ptr HostName;" & _
"dword HostNameLength;" & _
"word Port;" & _
"ptr UserName;" & _
"dword UserNameLength;" & _
"ptr Password;" & _
"dword PasswordLength;" & _
"ptr UrlPath;" & _
"dword UrlPathLength;" & _
"ptr ExtraInfo;" & _
"dword ExtraInfoLength")
DllStructSetData($tURL_COMPONENTS, 1, DllStructGetSize($tURL_COMPONENTS))
Local $tBuffers[6]
Local $iURLLen = StringLen($sURL)
For $i = 0 To 5
$tBuffers[$i] = DllStructCreate("wchar[" & $iURLLen + 1 & "]")
Next
DllStructSetData($tURL_COMPONENTS, "SchemeNameLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "SchemeName", DllStructGetPtr($tBuffers[0]))
DllStructSetData($tURL_COMPONENTS, "HostNameLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "HostName", DllStructGetPtr($tBuffers[1]))
DllStructSetData($tURL_COMPONENTS, "UserNameLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "UserName", DllStructGetPtr($tBuffers[2]))
DllStructSetData($tURL_COMPONENTS, "PasswordLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "Password", DllStructGetPtr($tBuffers[3]))
DllStructSetData($tURL_COMPONENTS, "UrlPathLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "UrlPath", DllStructGetPtr($tBuffers[4]))
DllStructSetData($tURL_COMPONENTS, "ExtraInfoLength", $iURLLen)
DllStructSetData($tURL_COMPONENTS, "ExtraInfo", DllStructGetPtr($tBuffers[5]))
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCrackUrl", _
"wstr", $sURL, _
"dword", $iURLLen, _
"dword", $iFlag, _
"ptr", DllStructGetPtr($tURL_COMPONENTS))
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Local $aRet[8] = [DllStructGetData($tBuffers[0], 1), _
DllStructGetData($tURL_COMPONENTS, "Scheme"), _
DllStructGetData($tBuffers[1], 1), _
DllStructGetData($tURL_COMPONENTS, "Port"), _
DllStructGetData($tBuffers[2], 1), _
DllStructGetData($tBuffers[3], 1), _
DllStructGetData($tBuffers[4], 1), _
DllStructGetData($tBuffers[5], 1)]
Return $aRet
EndFunc ;==>_WinHttpCrackUrl
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpCreateUrl
; Description ...: Creates a URL from array of components such as the host name and path.
; Syntax.........: _WinHttpCreateUrl($aURLArray)
; Parameters ....: $aURLArray - Array of URL data.
; Return values .: Success - Returns created URL
; Failure - Returns empty string and sets @error:
; |1 - Invalid input.
; |2 - Initial DllCall failed
; |3 - Main DllCall failed
; Author ........: ProgAndy
; Modified.......: trancexx
; Remarks .......: Input is one dimensional 8 elements in size array:
; |- first element [0] is scheme name
; |- second element [1] is internet protocol scheme
; |- third element [2] is host name
; |- fourth element [3] is port number
; |- fifth element [4] is user name
; |- sixth element [5] is password
; |- seventh element [6] is URL path
; |- eighth element [7] is extra information
; Related .......: _WinHttpCrackUrl
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384093(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpCreateUrl($aURLArray)
If UBound($aURLArray) - 8 Then Return SetError(1, 0, "")
Local $tURL_COMPONENTS = DllStructCreate("dword StructSize;" & _
"ptr SchemeName;" & _
"dword SchemeNameLength;" & _
"int Scheme;" & _
"ptr HostName;" & _
"dword HostNameLength;" & _
"word Port;" & _
"ptr UserName;" & _
"dword UserNameLength;" & _
"ptr Password;" & _
"dword PasswordLength;" & _
"ptr UrlPath;" & _
"dword UrlPathLength;" & _
"ptr ExtraInfo;" & _
"dword ExtraInfoLength;")
DllStructSetData($tURL_COMPONENTS, 1, DllStructGetSize($tURL_COMPONENTS))
Local $tBuffers[6][2]
$tBuffers[0][1] = StringLen($aURLArray[0])
If $tBuffers[0][1] Then
$tBuffers[0][0] = DllStructCreate("wchar[" & $tBuffers[0][1] + 1 & "]")
DllStructSetData($tBuffers[0][0], 1, $aURLArray[0])
EndIf
$tBuffers[1][1] = StringLen($aURLArray[2])
If $tBuffers[1][1] Then
$tBuffers[1][0] = DllStructCreate("wchar[" & $tBuffers[1][1] + 1 & "]")
DllStructSetData($tBuffers[1][0], 1, $aURLArray[2])
EndIf
$tBuffers[2][1] = StringLen($aURLArray[4])
If $tBuffers[2][1] Then
$tBuffers[2][0] = DllStructCreate("wchar[" & $tBuffers[2][1] + 1 & "]")
DllStructSetData($tBuffers[2][0], 1, $aURLArray[4])
EndIf
$tBuffers[3][1] = StringLen($aURLArray[5])
If $tBuffers[3][1] Then
$tBuffers[3][0] = DllStructCreate("wchar[" & $tBuffers[3][1] + 1 & "]")
DllStructSetData($tBuffers[3][0], 1, $aURLArray[5])
EndIf
$tBuffers[4][1] = StringLen($aURLArray[6])
If $tBuffers[4][1] Then
$tBuffers[4][0] = DllStructCreate("wchar[" & $tBuffers[4][1] + 1 & "]")
DllStructSetData($tBuffers[4][0], 1, $aURLArray[6])
EndIf
$tBuffers[5][1] = StringLen($aURLArray[7])
If $tBuffers[5][1] Then
$tBuffers[5][0] = DllStructCreate("wchar[" & $tBuffers[5][1] + 1 & "]")
DllStructSetData($tBuffers[5][0], 1, $aURLArray[7])
EndIf
DllStructSetData($tURL_COMPONENTS, "SchemeNameLength", $tBuffers[0][1])
DllStructSetData($tURL_COMPONENTS, "SchemeName", DllStructGetPtr($tBuffers[0][0]))
DllStructSetData($tURL_COMPONENTS, "HostNameLength", $tBuffers[1][1])
DllStructSetData($tURL_COMPONENTS, "HostName", DllStructGetPtr($tBuffers[1][0]))
DllStructSetData($tURL_COMPONENTS, "UserNameLength", $tBuffers[2][1])
DllStructSetData($tURL_COMPONENTS, "UserName", DllStructGetPtr($tBuffers[2][0]))
DllStructSetData($tURL_COMPONENTS, "PasswordLength", $tBuffers[3][1])
DllStructSetData($tURL_COMPONENTS, "Password", DllStructGetPtr($tBuffers[3][0]))
DllStructSetData($tURL_COMPONENTS, "UrlPathLength", $tBuffers[4][1])
DllStructSetData($tURL_COMPONENTS, "UrlPath", DllStructGetPtr($tBuffers[4][0]))
DllStructSetData($tURL_COMPONENTS, "ExtraInfoLength", $tBuffers[5][1])
DllStructSetData($tURL_COMPONENTS, "ExtraInfo", DllStructGetPtr($tBuffers[5][0]))
DllStructSetData($tURL_COMPONENTS, "Scheme", $aURLArray[1])
DllStructSetData($tURL_COMPONENTS, "Port", $aURLArray[3])
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCreateUrl", _
"ptr", DllStructGetPtr($tURL_COMPONENTS), _
"dword", $ICU_ESCAPE, _
"ptr", 0, _
"dword*", 0)
If @error Then Return SetError(2, 0, "")
Local $iURLLen = $aCall[4]
Local $URLBuffer = DllStructCreate("wchar[" & ($iURLLen + 1) & "]")
$aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCreateUrl", _
"ptr", DllStructGetPtr($tURL_COMPONENTS), _
"dword", $ICU_ESCAPE, _
"ptr", DllStructGetPtr($URLBuffer), _
"dword*", $iURLLen)
If @error Or Not $aCall[0] Then Return SetError(3, 0, "")
Return DllStructGetData($URLBuffer, 1)
EndFunc ;==>_WinHttpCreateUrl
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpDetectAutoProxyConfigUrl
; Description ...: Finds the URL for the Proxy Auto-Configuration (PAC) file.
; Syntax.........: _WinHttpDetectAutoProxyConfigUrl($iAutoDetectFlags)
; Parameters ....: $iAutoDetectFlags - Specifies what protocols to use to locate the PAC file.
; Return values .: Success - Returns URL for the PAC file.
; Failure - Returns empty string and sets @error:
; |1 - DllCall failed
; |2 - Internal failure.
; Author ........: trancexx
; Modified.......:
; Remarks .......: $iAutoDetectFlags values are defined in WinHttpconstants.au3
; Related .......: _WinHttpGetDefaultProxyConfiguration, _WinHttpGetIEProxyConfigForCurrentUser, _WinHttpSetDefaultProxyConfiguration
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384094(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpDetectAutoProxyConfigUrl($iAutoDetectFlags)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpDetectAutoProxyConfigUrl", "dword", $iAutoDetectFlags, "ptr*", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, "")
Local $pString = $aCall[2]
If $pString Then
Local $iLen = __WinHttpPtrStringLenW($pString)
If @error Then Return SetError(2, 0, "")
Local $tString = DllStructCreate("wchar[" & $iLen + 1 & "]", $pString)
Local $sString = DllStructGetData($tString, 1)
__WinHttpMemGlobalFree($pString)
Return $sString
EndIf
Return ""
EndFunc ;==>_WinHttpDetectAutoProxyConfigUrl
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpGetDefaultProxyConfiguration
; Description ...: Retrieves the default WinHttp proxy configuration.
; Syntax.........: _WinHttpGetDefaultProxyConfiguration()
; Parameters ....: None.
; Return values .: Success - Returns array with 3 elements:
; |$array[0] - Integer. Access type.
; |$array[1] - String. Proxy server list.
; |$array[2] - String. Proxy bypass list.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: Access types are defined in WinHttpconstants.au3:
; |$WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0
; |$WINHTTP_ACCESS_TYPE_NO_PROXY = 1
; |$WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3
; Related .......: _WinHttpDetectAutoProxyConfigUrl, _WinHttpGetIEProxyConfigForCurrentUser, _WinHttpSetDefaultProxyConfiguration
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384095(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpGetDefaultProxyConfiguration()
Local $tWINHTTP_PROXY_INFO = DllStructCreate("dword AccessType;" & _
"ptr Proxy;" & _
"ptr ProxyBypass")
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpGetDefaultProxyConfiguration", "ptr", DllStructGetPtr($tWINHTTP_PROXY_INFO))
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Local $iAccessType = DllStructGetData($tWINHTTP_PROXY_INFO, "AccessType")
Local $pProxy = DllStructGetData($tWINHTTP_PROXY_INFO, "Proxy")
Local $pProxyBypass = DllStructGetData($tWINHTTP_PROXY_INFO, "ProxyBypass")
Local $sProxy
If $pProxy Then
Local $iProxyLen = __WinHttpPtrStringLenW($pProxy)
If Not @error Then
Local $tProxy = DllStructCreate("wchar[" & $iProxyLen + 1 & "]", $pProxy)
$sProxy = DllStructGetData($tProxy, 1)
__WinHttpMemGlobalFree($pProxy)
EndIf
EndIf
Local $sProxyBypass
If $pProxyBypass Then
Local $iProxyBypassLen = __WinHttpPtrStringLenW($pProxyBypass)
If Not @error Then
Local $tProxyBypass = DllStructCreate("wchar[" & $iProxyBypassLen + 1 & "]", $pProxyBypass)
$sProxyBypass = DllStructGetData($tProxyBypass, 1)
__WinHttpMemGlobalFree($pProxyBypass)
EndIf
EndIf
Local $aRet[3] = [$iAccessType, $sProxy, $sProxyBypass]
Return $aRet
EndFunc ;==>_WinHttpGetDefaultProxyConfiguration
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpGetIEProxyConfigForCurrentUser
; Description ...: Retrieves the Internet Explorer proxy configuration for the current user.
; Syntax.........: _WinHttpGetIEProxyConfigForCurrentUser()
; Parameters ....: None.
; Return values .: Success - Returns array with 4 elements:
; |$array[0] - if 1 indicates that the Internet Explorer proxy configuration for the current user specifies "automatically detect settings",
; |$array[1] - auto-configuration URL if the Internet Explorer proxy configuration for the current user specifies "Use automatic proxy configuration",
; |$array[2] - proxy URL if the Internet Explorer proxy configuration for the current user specifies "use a proxy server",
; |$array[3] - optional proxy by-pass server list.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; |2 - Internal failure.
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpDetectAutoProxyConfigUrl, _WinHttpGetDefaultProxyConfiguration, _WinHttpSetDefaultProxyConfiguration
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384096(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpGetIEProxyConfigForCurrentUser()
Local $tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG = DllStructCreate("int AutoDetect;" & _
"ptr AutoConfigUrl;" & _
"ptr Proxy;" & _
"ptr ProxyBypass;")
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpGetIEProxyConfigForCurrentUser", "ptr", DllStructGetPtr($tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG))
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Local $iAutoDetect = DllStructGetData($tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG, "AutoDetect")
Local $pAutoConfigUrl = DllStructGetData($tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG, "AutoConfigUrl")
Local $pProxy = DllStructGetData($tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG, "Proxy")
Local $pProxyBypass = DllStructGetData($tWINHTTP_CURRENT_USER_IE_PROXY_CONFIG, "ProxyBypass")
Local $sAutoConfigUrl
If $pAutoConfigUrl Then
Local $iAutoConfigUrlLen = __WinHttpPtrStringLenW($pAutoConfigUrl)
If Not @error Then
Local $tAutoConfigUrl = DllStructCreate("wchar[" & $iAutoConfigUrlLen + 1 & "]", $pAutoConfigUrl)
$sAutoConfigUrl = DllStructGetData($tAutoConfigUrl, 1)
__WinHttpMemGlobalFree($pAutoConfigUrl)
EndIf
EndIf
Local $sProxy
If $pProxy Then
Local $iProxyLen = __WinHttpPtrStringLenW($pProxy)
If Not @error Then
Local $tProxy = DllStructCreate("wchar[" & $iProxyLen + 1 & "]", $pProxy)
$sProxy = DllStructGetData($tProxy, 1)
__WinHttpMemGlobalFree($pProxy)
EndIf
EndIf
Local $sProxyBypass
If $pProxyBypass Then
Local $iProxyBypassLen = __WinHttpPtrStringLenW($pProxyBypass)
If Not @error Then
Local $tProxyBypass = DllStructCreate("wchar[" & $iProxyBypassLen + 1 & "]", $pProxyBypass)
$sProxyBypass = DllStructGetData($tProxyBypass, 1)
__WinHttpMemGlobalFree($pProxyBypass)
EndIf
EndIf
Local $aOutput[4] = [$iAutoDetect, $sAutoConfigUrl, $sProxy, $sProxyBypass]
Return $aOutput
EndFunc ;==>_WinHttpGetIEProxyConfigForCurrentUser
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpOpen
; Description ...: Initializes the use of WinHttp functions and returns a WinHttp-session handle.
; Syntax.........: _WinHttpOpen([$sUserAgent = Default [, $iAccessType = Default [, $sProxyName = Default [, $sProxyBypass = Default [, $iFlag = Default ]]]]])
; Parameters ....: $sUserAgent - [optional] The name of the application or entity calling the WinHttp functions. Default is "AutoIt/3.3".
; $iAccessType - [optional] Type of access required. Default is $WINHTTP_ACCESS_TYPE_NO_PROXY.
; $sProxyName - [optional] The name of the proxy server to use when proxy access is specified by setting $iAccessType to $WINHTTP_ACCESS_TYPE_NAMED_PROXY. Default is $WINHTTP_NO_PROXY_NAME.
; $sProxyBypass - [optional] An optional list of host names or IP addresses, or both, that should not be routed through the proxy when $iAccessType is set to $WINHTTP_ACCESS_TYPE_NAMED_PROXY. Default is $WINHTTP_NO_PROXY_BYPASS.
; $iFlag - [optional] Integer containing the flags that indicate various options affecting the behavior of this function. Default is 0.
; Return values .: Success - Returns valid session handle.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: For asynchronous mode set $iFlag to $WINHTTP_FLAG_ASYNC
; Related .......: _WinHttpCloseHandle, _WinHttpConnect
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384098(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpOpen($sUserAgent = Default, $iAccessType = Default, $sProxyName = Default, $sProxyBypass = Default, $iFlag = Default)
__WinHttpDefault($sUserAgent, "AutoIt/3.3")
__WinHttpDefault($iAccessType, $WINHTTP_ACCESS_TYPE_NO_PROXY)
__WinHttpDefault($sProxyName, $WINHTTP_NO_PROXY_NAME)
__WinHttpDefault($sProxyBypass, $WINHTTP_NO_PROXY_BYPASS)
__WinHttpDefault($iFlag, 0)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpOpen", _
"wstr", $sUserAgent, _
"dword", $iAccessType, _
"wstr", $sProxyName, _
"wstr", $sProxyBypass, _
"dword", $iFlag)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return $aCall[0]
EndFunc ;==>_WinHttpOpen
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpOpenRequest
; Description ...: Creates an HTTP request handle.
; Syntax.........: _WinHttpOpenRequest($hConnect [, $sVerb = Default [, $sObjectName = Default [, $sVersion = Default [, $sReferrer = Default [, $sAcceptTypes = Default [, $iFlags = Default ]]]]]])
; Parameters ....: $hConnect - Handle to an HTTP session returned by _WinHttpConnect().
; $sVerb - [optional] HTTP verb to use in the request. Default is "GET".
; $sObjectName - [optional] The name of the target resource of the specified HTTP verb.
; $sVersion - [optional] HTTP version. Default is "HTTP/1.1"
; $sReferrer - [optional] URL of the document from which the URL in the request $sObjectName was obtained. Default is $WINHTTP_NO_REFERER.
; $sAcceptTypes - [optional] Media types accepted by the client. Default is $WINHTTP_DEFAULT_ACCEPT_TYPES
; $iFlags - [optional] Integer specifying the Internet flag values. Default is $WINHTTP_FLAG_ESCAPE_DISABLE
; Return values .: Success - Returns valid session handle.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpCloseHandle, _WinHttpConnect, _WinHttpSendRequest
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384099(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpOpenRequest($hConnect, $sVerb = Default, $sObjectName = Default, $sVersion = Default, $sReferrer = Default, $sAcceptTypes = Default, $iFlags = Default)
__WinHttpDefault($sVerb, "GET")
__WinHttpDefault($sObjectName, "")
__WinHttpDefault($sVersion, "HTTP/1.1")
__WinHttpDefault($sReferrer, $WINHTTP_NO_REFERER)
__WinHttpDefault($iFlags, $WINHTTP_FLAG_ESCAPE_DISABLE)
Local $pAcceptTypes
If $sAcceptTypes = Default Or Number($sAcceptTypes) = -1 Then
$pAcceptTypes = $WINHTTP_DEFAULT_ACCEPT_TYPES
Else
Local $aTypes = StringSplit($sAcceptTypes, ",", 2)
Local $tAcceptTypes = DllStructCreate("ptr[" & UBound($aTypes) + 1 & "]")
Local $tType[UBound($aTypes)]
For $i = 0 To UBound($aTypes) - 1
$tType[$i] = DllStructCreate("wchar[" & StringLen($aTypes[$i]) + 1 & "]")
DllStructSetData($tType[$i], 1, $aTypes[$i])
DllStructSetData($tAcceptTypes, 1, DllStructGetPtr($tType[$i]), $i + 1)
Next
$pAcceptTypes = DllStructGetPtr($tAcceptTypes)
EndIf
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpOpenRequest", _
"handle", $hConnect, _
"wstr", StringUpper($sVerb), _
"wstr", $sObjectName, _
"wstr", StringUpper($sVersion), _
"wstr", $sReferrer, _
"ptr", $pAcceptTypes, _
"dword", $iFlags)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return $aCall[0]
EndFunc ;==>_WinHttpOpenRequest
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpQueryDataAvailable
; Description ...: Returns the availability to be read with _WinHttpReadData().
; Syntax.........: _WinHttpQueryDataAvailable($hRequest)
; Parameters ....: $hRequest - handle returned by _WinHttpOpenRequest().
; Return values .: Success - Returns 1 if data is available.
; - Returns 0 if no data is available.
; - @extended receives the number of available bytes.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: _WinHttpReceiveResponse must have been called for this handle and completed before _WinHttpQueryDataAvailable is called.
; Related .......: _WinHttpOpenRequest, _WinHttpReadData, _WinHttpReceiveResponse
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384101(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpQueryDataAvailable($hRequest)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryDataAvailable", "handle", $hRequest, "dword*", 0)
If @error Then Return SetError(1, 0, 0)
Return SetExtended($aCall[2], $aCall[0])
EndFunc ;==>_WinHttpQueryDataAvailable
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpQueryHeaders
; Description ...: Retrieves header information associated with an HTTP request.
; Syntax.........: _WinHttpQueryHeaders($hRequest [, $iInfoLevel = Default [, $sName = Default [, $iIndex = Default ]]])
; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest().
; $iInfoLevel - [optional] A combination of attribute and modifier flags. Default is $WINHTTP_QUERY_RAW_HEADERS_CRLF.
; $sName - [optional] Header name string. Default is $WINHTTP_HEADER_NAME_BY_INDEX.
; $iIndex - [optional] Index used to enumerate multiple headers with the same name
; Return values .: Success - Returns string that contains header.
; - @extended is set to the index of the next header
; Failure - Returns empty string and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpAddRequestHeaders, _WinHttpOpenRequest
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384102(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpQueryHeaders($hRequest, $iInfoLevel = Default, $sName = Default, $iIndex = Default)
__WinHttpDefault($iInfoLevel, $WINHTTP_QUERY_RAW_HEADERS_CRLF)
__WinHttpDefault($sName, $WINHTTP_HEADER_NAME_BY_INDEX)
__WinHttpDefault($iIndex, $WINHTTP_NO_HEADER_INDEX)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryHeaders", _
"handle", $hRequest, _
"dword", $iInfoLevel, _
"wstr", $sName, _
"wstr", "", _
"dword*", 65536, _
"dword*", $iIndex)
If @error Or Not $aCall[0] Then Return SetError(1, 0, "")
Return SetExtended($aCall[6], $aCall[4])
EndFunc ;==>_WinHttpQueryHeaders
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpQueryOption
; Description ...: Queries an Internet option on the specified handle.
; Syntax.........: _WinHttpQueryOption($hInternet, $iOption)
; Parameters ....: $hInternet - Handle on which to query information.
; $iOption - Internet option to query.
; Return values .: Success - Returns data containing requested information.
; Failure - Returns empty string and sets @error:
; |1 - Initial DllCall failed
; |2 - Main DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: Type of the returned data varies on request.
; Related .......: _WinHttpSetOption
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384103(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpQueryOption($hInternet, $iOption)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", _
"handle", $hInternet, _
"dword", $iOption, _
"ptr", 0, _
"dword*", 0)
If @error Or $aCall[0] Then Return SetError(1, 0, "")
Local $iSize = $aCall[4]
Local $tBuffer
Switch $iOption
Case $WINHTTP_OPTION_CONNECTION_INFO, $WINHTTP_OPTION_PASSWORD, $WINHTTP_OPTION_PROXY_PASSWORD, $WINHTTP_OPTION_PROXY_USERNAME, $WINHTTP_OPTION_URL, $WINHTTP_OPTION_USERNAME, $WINHTTP_OPTION_USER_AGENT, _
$WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT, $WINHTTP_OPTION_PASSPORT_COBRANDING_URL
$tBuffer = DllStructCreate("wchar[" & $iSize + 1 & "]")
Case $WINHTTP_OPTION_PARENT_HANDLE, $WINHTTP_OPTION_CALLBACK
$tBuffer = DllStructCreate("ptr")
Case $WINHTTP_OPTION_CONNECT_TIMEOUT, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM, _
$WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, $WINHTTP_OPTION_CONNECT_RETRIES, $WINHTTP_OPTION_EXTENDED_ERROR, $WINHTTP_OPTION_HANDLE_TYPE, $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER, _
$WINHTTP_OPTION_MAX_CONNS_PER_SERVER, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, $WINHTTP_OPTION_RECEIVE_TIMEOUT, _
$WINHTTP_OPTION_RESOLVE_TIMEOUT, $WINHTTP_OPTION_SECURITY_FLAGS, $WINHTTP_OPTION_SECURITY_KEY_BITNESS, $WINHTTP_OPTION_SEND_TIMEOUT
$tBuffer = DllStructCreate("int")
Case Else
$tBuffer = DllStructCreate("byte[" & $iSize & "]")
EndSwitch
$aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", _
"handle", $hInternet, _
"dword", $iOption, _
"ptr", DllStructGetPtr($tBuffer), _
"dword*", $iSize)
If @error Or Not $aCall[0] Then Return SetError(2, 0, "")
Return DllStructGetData($tBuffer, 1)
EndFunc ;==>_WinHttpQueryOption
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpReadData
; Description ...: Reads data from a handle opened by the _WinHttpOpenRequest() function.
; Syntax.........: _WinHttpReadData($hRequest [, $iMode = Default [, $iNumberOfBytesToRead = Default ]])
; Parameters ....: $hRequest - Valid handle returned from a previous call to _WinHttpOpenRequest().
; $iMode - [optional] Integer representing reading mode. Default is 0 (charset is decoded as it is ANSI).
; $iNumberOfBytesToRead - [optional] The number of bytes to read. Default is 8192 bytes.
; Return values .: Success - Returns data read.
; - @extended receives the number of bytes read.
; Special: Sets @error to -1 if no more data to read (end reached).
; Failure - Returns empty string and sets @error:
; |1 - DllCall failed
; Author ........: trancexx, ProgAndy
; Modified.......:
; Remarks .......: $iMode can have these values:
; |0 - ANSI
; |1 - UTF8
; |2 - Binary
; Related .......: _WinHttpOpenRequest, _WinHttpWriteData
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384104(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpReadData($hRequest, $iMode = Default, $iNumberOfBytesToRead = Default, $pBuffer = Default)
__WinHttpDefault($iMode, 0)
__WinHttpDefault($iNumberOfBytesToRead, 8192)
Local $tBuffer
Switch $iMode
Case 1, 2
If $pBuffer And $pBuffer <> Default Then
$tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]", $pBuffer)
Else
$tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
EndIf
Case Else
$iMode = 0
If $pBuffer And $pBuffer <> Default Then
$tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]", $pBuffer)
Else
$tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")
EndIf
EndSwitch
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReadData", _
"handle", $hRequest, _
"ptr", DllStructGetPtr($tBuffer), _
"dword", $iNumberOfBytesToRead, _
"dword*", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, "")
If Not $aCall[4] Then Return SetError(-1, 0, "")
If $aCall[4] < $iNumberOfBytesToRead Then
Switch $iMode
Case 0
Return SetExtended($aCall[4], StringLeft(DllStructGetData($tBuffer, 1), $aCall[4]))
Case 1
Return SetExtended($aCall[4], BinaryToString(BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]), 4))
Case 2
Return SetExtended($aCall[4], BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]))
EndSwitch
Else
Switch $iMode
Case 0, 2
Return SetExtended($aCall[4], DllStructGetData($tBuffer, 1))
Case 1
Return SetExtended($aCall[4], BinaryToString(DllStructGetData($tBuffer, 1), 4))
EndSwitch
EndIf
EndFunc ;==>_WinHttpReadData
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpReceiveResponse
; Description ...: Waits to receive the response to an HTTP request initiated by WinHttpSendRequest().
; Syntax.........: _WinHttpReceiveResponse($hRequest)
; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest() and sent by _WinHttpSendRequest().
; Return values .: Success - Returns 1.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: Call to _WinHttpReceiveResponse() must be done before _WinHttpQueryDataAvailable() and _WinHttpReadData().
; Related .......: _WinHttpOpenRequest, _WinHttpSetTimeouts
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384105(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpReceiveResponse($hRequest)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReceiveResponse", "handle", $hRequest, "ptr", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpReceiveResponse
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSendRequest
; Description ...: Sends the specified request to the HTTP server.
; Syntax.........: _WinHttpSendRequest($hRequest [, $sHeaders = Default [, $sOptional = Default [, $iTotalLength = Default [, $iContext = Default ]]]])
; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest().
; $sHeaders - [optional] Additional headers to append to the request. Default is $WINHTTP_NO_ADDITIONAL_HEADERS.
; $sOptional - [optional] Optional data to send immediately after the request headers. Default is $WINHTTP_NO_REQUEST_DATA.
; $iTotalLength - [optional] Length, in bytes, of the total optional data sent. Default is 0.
; $iContext - [optional] Application-defined value that is passed, with the request handle, to any callback functions. Default is 0.
; Return values .: Success - Returns 1.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......: Specifying optional data ($sOptional) will cause $iTotalLength to receive the size of that data if left default value.
; Related .......: _WinHttpOpenRequest
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384110(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpSendRequest($hRequest, $sHeaders = Default, $sOptional = Default, $iTotalLength = Default, $iContext = Default)
__WinHttpDefault($sHeaders, $WINHTTP_NO_ADDITIONAL_HEADERS)
__WinHttpDefault($sOptional, $WINHTTP_NO_REQUEST_DATA)
__WinHttpDefault($iTotalLength, 0)
__WinHttpDefault($iContext, 0)
Local $pOptional = 0, $iOptionalLength = 0
If @NumParams > 2 Then
Local $tOptional
$iOptionalLength = BinaryLen($sOptional)
$tOptional = DllStructCreate("byte[" & $iOptionalLength & "]")
If $iOptionalLength Then $pOptional = DllStructGetPtr($tOptional)
DllStructSetData($tOptional, 1, $sOptional)
EndIf
If Not $iTotalLength Or $iTotalLength < $iOptionalLength Then $iTotalLength += $iOptionalLength
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSendRequest", _
"handle", $hRequest, _
"wstr", $sHeaders, _
"dword", 0, _
"ptr", $pOptional, _
"dword", $iOptionalLength, _
"dword", $iTotalLength, _
"dword_ptr", $iContext)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpSendRequest
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSetCredentials
; Description ...: Passes the required authorization credentials to the server.
; Syntax.........: _WinHttpSetCredentials($hRequest, $iAuthTargets, $iAuthScheme, $sUserName, $sPassword)
; Parameters ....: $hRequest - Valid handle returned by _WinHttpOpenRequest().
; $iAuthTargets - Authentication target.
; $iAuthScheme - Authentication scheme.
; $sUserName - Valid user name.
; $sPassword - Valid password.
; Return values .: Success - Returns 1.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpOpenRequest
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384112(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpSetCredentials($hRequest, $iAuthTargets, $iAuthScheme, $sUserName, $sPassword)
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetCredentials", _
"handle", $hRequest, _
"dword", $iAuthTargets, _
"dword", $iAuthScheme, _
"wstr", $sUserName, _
"wstr", $sPassword, _
"ptr", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpSetCredentials
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSetDefaultProxyConfiguration
; Description ...: Sets the default WinHttp proxy configuration.
; Syntax.........: _WinHttpSetDefaultProxyConfiguration($iAccessType [, $sProxy = "" [, $sProxyBypass = ""])
; Parameters ....: $iAccessType - Integer. Access type.
; $sProxy - [optional] String. Proxy server list.
; $sProxyBypass - [optional] String. Proxy bypass list.
; Return values .: Success - Returns 1.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpDetectAutoProxyConfigUrl, _WinHttpGetDefaultProxyConfiguration, _WinHttpGetIEProxyConfigForCurrentUser
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384113(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpSetDefaultProxyConfiguration($iAccessType, $sProxy = "", $sProxyBypass = "")
Local $tProxy = DllStructCreate("wchar[" & StringLen($sProxy) + 1 & "]")
DllStructSetData($tProxy, 1, $sProxy)
Local $tProxyBypass = DllStructCreate("wchar[" & StringLen($sProxyBypass) + 1 & "]")
DllStructSetData($tProxyBypass, 1, $sProxyBypass)
Local $tWINHTTP_PROXY_INFO = DllStructCreate("dword AccessType;" & _
"ptr Proxy;" & _
"ptr ProxyBypass")
DllStructSetData($tWINHTTP_PROXY_INFO, "AccessType", $iAccessType)
If $iAccessType <> $WINHTTP_ACCESS_TYPE_NO_PROXY Then
DllStructSetData($tWINHTTP_PROXY_INFO, "Proxy", DllStructGetPtr($tProxy))
DllStructSetData($tWINHTTP_PROXY_INFO, "ProxyBypass", DllStructGetPtr($tProxyBypass))
EndIf
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetDefaultProxyConfiguration", "ptr", DllStructGetPtr($tWINHTTP_PROXY_INFO))
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc ;==>_WinHttpSetDefaultProxyConfiguration
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSetOption
; Description ...: Sets an Internet option.
; Syntax.........: _WinHttpSetOption($hInternet, $iOption, $vSetting [, $iSize = Default ])
; Parameters ....: $hInternet - Handle on which to set data.
; $iOption - Integer value that contains the Internet option to set.
; $vSetting - Value of setting
; $iSize - [optional] Size of $vSetting, required if $vSetting is pointer to memory block
; Return values .: Success - Returns 1.
; Failure - Returns 0 and sets @error:
; |1 - Invalid Internet option
; |2 - Size required
; |3 - Datatype of value does not fit to option
; |4 - DllCall failed
; Author ........: ProgAndy, trancexx
; Modified.......:
; Remarks .......:
; Related .......: _WinHttpQueryOption
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384114(VS.85).aspx
; Example .......:
;============================================================================================
Func _WinHttpSetOption($hInternet, $iOption, $vSetting, $iSize = Default)
If $iSize = Default Then $iSize = -1
If IsBinary($vSetting) Then
$iSize = DllStructCreate("byte[" & BinaryLen($vSetting) & "]")
DllStructSetData($iSize, 1, $vSetting)
$vSetting = $iSize
$iSize = DllStructGetSize($vSetting)
EndIf
Local $sType
Switch $iOption
Case $WINHTTP_OPTION_AUTOLOGON_POLICY, $WINHTTP_OPTION_CODEPAGE, $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, $WINHTTP_OPTION_CONNECT_RETRIES, _
$WINHTTP_OPTION_CONNECT_TIMEOUT, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_OPTION_ENABLE_FEATURE, $WINHTTP_OPTION_ENABLETRACING, _
$WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER, $WINHTTP_OPTION_MAX_CONNS_PER_SERVER, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, _
$WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE, $WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, $WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, _
$WINHTTP_OPTION_READ_BUFFER_SIZE, $WINHTTP_OPTION_RECEIVE_TIMEOUT, _
$WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REJECT_USERPWD_IN_URL, _
$WINHTTP_OPTION_REQUEST_PRIORITY, $WINHTTP_OPTION_RESOLVE_TIMEOUT, $WINHTTP_OPTION_SECURE_PROTOCOLS, $WINHTTP_OPTION_SECURITY_FLAGS, _
$WINHTTP_OPTION_SECURITY_KEY_BITNESS, $WINHTTP_OPTION_SEND_TIMEOUT, $WINHTTP_OPTION_SPN, $WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS, _
$WINHTTP_OPTION_WORKER_THREAD_COUNT, $WINHTTP_OPTION_WRITE_BUFFER_SIZE
$sType = "dword*"
$iSize = 4
Case $WINHTTP_OPTION_CALLBACK, $WINHTTP_OPTION_PASSPORT_SIGN_OUT
$sType = "ptr*"
$iSize = 4
If @AutoItX64 Then $iSize = 8
If Not IsPtr($vSetting) Then Return SetError(3, 0, 0)
Case $WINHTTP_OPTION_CONTEXT_VALUE
$sType = "dword_ptr"
$iSize = 4
If @AutoItX64 Then $iSize = 8
Case $WINHTTP_OPTION_PASSWORD, $WINHTTP_OPTION_PROXY_PASSWORD, $WINHTTP_OPTION_PROXY_USERNAME, $WINHTTP_OPTION_USER_AGENT, $WINHTTP_OPTION_USERNAME
$sType = "wstr"
If (IsDllStruct($vSetting) Or IsPtr($vSetting)) Then Return SetError(3, 0, 0)
If $iSize < 1 Then $iSize = StringLen($vSetting)
Case $WINHTTP_OPTION_CLIENT_CERT_CONTEXT, $WINHTTP_OPTION_GLOBAL_PROXY_CREDS, $WINHTTP_OPTION_GLOBAL_SERVER_CREDS, $WINHTTP_OPTION_HTTP_VERSION, _
$WINHTTP_OPTION_PROXY
$sType = "ptr"
If Not (IsDllStruct($vSetting) Or IsPtr($vSetting)) Then Return SetError(3, 0, 0)
Case Else
Return SetError(1, 0, 0)
EndSwitch
If $iSize < 1 Then
If IsDllStruct($vSetting) Then
$iSize = DllStructGetSize($vSetting)
Else
Return SetError(2, 0, 0)
EndIf
EndIf
Local $aCall
If IsDllStruct($vSetting) Then
$aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, DllStructGetPtr($vSetting), "dword", $iSize)
Else
$aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, $vSetting, "dword", $iSize)
EndIf
If @error Or Not $aCall[0] Then Return SetError(4, 0, 0)
Return 1
EndFunc ;==>_WinHttpSetOption
; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSetStatusCallback
; Description ...: Sets up a callback function that WinHttp can call as progress is made during an operation.
; Syntax.........: _WinHttpSetStatusCallback($hInternet, $hInternetCallback [, $iNotificationFlags = Default ])
; Parameters ....: $hInternet - Handle for which the callback is to be set.
; $hInternetCallback - Callback function to call when progress is made.
; $iNotificationFlags - [optional] Flags to indicate which events activate the callback function. Default is $WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS.
; Return values .: Success - Returns a pointer to the previously defined status callback function or NULL if there was no previously defined status callback function.
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed
; Author ........: ProgAndy
; Modified.......: trancexx