Hi lexvictory,
I'm glad to hear it works! Thanks.
Sorry, the code above was pulled and trimmed to just show the klurgy bits. Here is the full routine as it is at the moment:
Code: Select all
Procedure httpPost(server.s, item.s, file.s, dta.l, dLen.l, *bfr.l, prog.l = 0)
Protected hInet.l
Protected hUrl.l
Protected hConn.l
Protected hOpen.l
Protected hSend.l
Protected hAdd.l
Protected wrk.s
Protected rcvd.l
Protected pgSz.l
Protected i.l
Protected bufSz.l = 1024
Protected hdrSz.l = 4096
Protected bufLen.l
Protected httpFetchFileCB.proto_httpFetchFileCB
httpFetchFileCB = prog
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 = "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)
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
wrk = PeekS(*bfr,hdrSz*SizeOf(character))
PokeS(*bfr,wrk,Len(wrk),#PB_Ascii)
bufLen = Len(wrk)
pgSz = Val(httpGetHeader(wrk,"Content-Length:"))
Else
pgSz = 0
bufLen = 0
EndIf
rcvd = 0
Repeat
*bfr = ReAllocateMemory(*bfr,bufLen+(bufSz))
InternetReadFile_(hOpen,*bfr + bufLen,bufSz,@rcvd)
bufLen + rcvd
If prog <> 0
httpFetchFileCB(bufLen,0)
EndIf
Until rcvd = 0
InternetCloseHandle_(hInet)
ProcedureReturn bufLen
EndProcedure
; .. stuff
bfr=AllocateMemory(1)
i = httpPost(server, item, "", @dta, Len(dta), bfr, 0, 0)
if i
wrk=PeekS(bfr,i,#PB_Ascii)
; .. stuff
EndIf
FreeMemory(bfr)
The "i" is the returned buffer length.
It is a bit untidy, showing mods on the fly until it worked; with the save to file (Create,WriteData,Close) missing; and with error checking things like
If hInet stripped out.