I want to access a REST API to download a file that requires a token in the "Authorization:" key. I cannot use ReceiveHTTPFile() because there is no option to include the token in the header. I tried using OpenNetworkConnection(), SendNetworkString and then ReceiveNetworkData. All I receive is an html page with various messages but not the file. If I try it in PostMan everything works. So I wondering what I did wrong.
Below is a some sample code I used for testing. The key shown in the code is fake but the result I received shown below was generated with the real key. The actual URL is https://beta.gvmunifi.com/api/sentinel/ ... pdates/zip
Code: Select all
#AuthKey = "MagdfgdCUfghjffjgfgjZKg8" ; Fake key
lnConn.i = OpenNetworkConnection("beta.gvmunifi.com",443,#PB_Network_TCP,5000)
If lnConn
If SendNetworkString(lnConn,"GET /api/sentinel/KARDTECHLAB1/updates/zip"+#CRLF$+
"Authorization: "+#AuthKey+#CRLF$+
"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"+#CRLF$+
"Accept: */*"+#CRLF$+"Cache-Control: no-cache"+#CRLF$+
"Host: beta.gvmunifi.com"+#CRLF$+
"Accept-Encoding: gzip, deflate, br"+#CRLF$+
"Connection: keep-alive"+#CRLF$+#CRLF$)
*rxBuffer=AllocateMemory(1500)
lnLen = ReceiveNetworkData(lnConn,*rxBuffer,1500)
ShowMemoryViewer(*rxBuffer,750)
FreeMemory(*rxBuffer)
EndIf
CloseNetworkConnection(lnConn)
EndIf
; Result when using the real key
; 0000000028F42818 3C 68 74 6D 6C 3E 0D 0A 3C 68 65 61 64 3E 3C 74 <html>..<head><t
; 0000000028F42828 69 74 6C 65 3E 34 30 30 20 54 68 65 20 70 6C 61 itle>400 The pla
; 0000000028F42838 69 6E 20 48 54 54 50 20 72 65 71 75 65 73 74 20 in HTTP request
; 0000000028F42848 77 61 73 20 73 65 6E 74 20 74 6F 20 48 54 54 50 was sent To HTTP
; 0000000028F42858 53 20 70 6F 72 74 3C 2F 74 69 74 6C 65 3E 3C 2F S port</title></
; 0000000028F42868 68 65 61 64 3E 0D 0A 3C 62 6F 64 79 3E 0D 0A 3C head>..<body>..<
; 0000000028F42878 63 65 6E 74 65 72 3E 3C 68 31 3E 34 30 30 20 42 center><h1>400 B
; 0000000028F42888 61 64 20 52 65 71 75 65 73 74 3C 2F 68 31 3E 3C ad Request</h1><
; 0000000028F42898 2F 63 65 6E 74 65 72 3E 0D 0A 3C 63 65 6E 74 65 /center>..<cente
; 0000000028F428A8 72 3E 54 68 65 20 70 6C 61 69 6E 20 48 54 54 50 r>The plain HTTP
; 0000000028F428B8 20 72 65 71 75 65 73 74 20 77 61 73 20 73 65 6E request was sen
; 0000000028F428C8 74 20 74 6F 20 48 54 54 50 53 20 70 6F 72 74 3C t To HTTPS port<
; 0000000028F428D8 2F 63 65 6E 74 65 72 3E 0D 0A 3C 68 72 3E 3C 63 /center>..<hr><c
; 0000000028F428E8 65 6E 74 65 72 3E 63 6C 6F 75 64 66 6C 61 72 65 enter>cloudflare
; 0000000028F428F8 3C 2F 63 65 6E 74 65 72 3E 0D 0A 3C 2F 62 6F 64 </center>..</bod
; 0000000028F42908 79 3E 0D 0A 3C 2F 68 74 6D 6C 3E 0D 0A 00 00 00 y>..</html>.....
; 0000000028F42918 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
; 0000000028F42928 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................