Hi lexvictory, stripped code below (all checks, progress calls, etc, pulled out leaving, hopefully, only the significant bits and not too messy despite the missing bits). Treat as psuedo code.
Code: Select all
; --------------------- these bits handled outside subroutine and passed in
; either as globals or as parameters.
netAgent.s = "My Client's 'browser' Name"
server.s = "127.0.0.1"
item.s = "/MyVirtualDomain/wwwRoot/someFolder/somePage.asp"
dta.s = "P1=One&P2=Two"
dLen = Len(dta)
*bfr = AllocateMemory(1)
hdrSz = 1024
bufSz = 1024
; --------------------- This is the subroutine
; --------------------- Following works as-is, strings accepted as-is
hInet = InternetOpen_(netAgent, #INTERNET_OPEN_TYPE_DIRECT, #Null,#Null,0)
hConn = InternetConnect_(hInet,server, #INTERNET_DEFAULT_HTTP_PORT, #Null,#Null, #INTERNET_SERVICE_HTTP,0,0)
hOpen = HttpOpenRequest_(hConn,"POST",item, #Null,#Null,0, #INTERNET_FLAG_RELOAD,0)
wrk.s = "Content-Type: application/x-www-form-urlencoded"+Chr(13)+Chr(10)
hAdd = HttpAddRequestHeaders_(hOpen,@wrk,Len(wrk),#HTTP_ADDREQ_FLAG_ADD|#HTTP_ADDREQ_FLAG_REPLACE)
; --------------------- Need to klurge post data
wrk = Space(dLen)
PokeS(@wrk,PeekS(dta,dLen),dLen,#PB_Ascii)
hSend = HttpSendRequest_(hOpen,0,0,@wrk,dLen)
ReAllocateMemory(*bfr,hdrSz)
i = HttpQueryInfo_(hOpen,#HTTP_QUERY_RAW_HEADERS_CRLF,*bfr,@hdrSz,0)
If i
; --------------------- Came back as unicode so ASCII it at start of buffer
wrk = PeekS(*bfr,hdrSz*SizeOf(character))
PokeS(*bfr,wrk,Len(wrk),#PB_Ascii)
bufLen = Len(wrk)
pgSz = Val(httpGetHeader(wrk,"Content-Length:"))
; --------------------- httpGetHeader above is just a procedure that grabs the value
Else
pgSz = 0
bufLen = 0
EndIf
rcvd = 0
Repeat
*bfr = ReAllocateMemory(*bfr,bufLen+(bufSz))
InternetReadFile_(hOpen,*bfr + bufLen,bufSz,@rcvd)
bufLen + rcvd
Until rcvd = 0
InternetCloseHandle_(hInet)
; ---------------------
; Note: The contents of buffer are:
; the header (unicode PokeS(PeekS())-ed to ascii
; the page - arrived as ascii
; ---------------------
; Now get it as ascii into a usable unicode format
wrk=PeekS(*bfr,i,#PB_Ascii)
So:
Some stuff (like content type, server name and page (item) path) sent as unicode. Post data sent as Ascii. Any other mix fails both on my localhost and with online servers.
Header comes back as unicode (but actually, may have been UTF8 - only parts were garbled). Actual page arrived as plain old Ascii.
I can try using #PB_UTF8 flag with the PeekS/PokeS stuff, but that still has the fiddling around. And as you say, ASCII will work. Also, as you pointed out, it seems that headers are unicode, whilst data (in) and page (back) are not. Haven't tried with a plain old GET yet.
If what I am doing is safe, then I am happy enough with it. I just want to be sure it is safe and not just a happenstance that it is working.
If you can help, much appreciated. If you can't, I still appreciate the effort and interest you showed. Thanks!

@}--`--,-- A rose by any other name ..