Page 2 of 2

Posted: Mon May 29, 2006 3:12 pm
by Dare
:D

Hi thalius, if I dont do this:
PokeS(@wrk,PeekS(dta,dLen),dLen,#PB_Ascii)
for the post data (in unicode mode) then the server gets zip. A simple script like
Response.write "[" & Request.Form("name") & "]"
will output "[]".

Edit: Ditto with the incoming headers klurge.


But the original snippet I posted above is working for me, and seems to be standing up. Perhaps it is a safe solution.


BTW, my urlencode routine doesn't encode the "?" and "&" in the querystring otherwise it confuses the server. So in unicode mode ...? But - note to me - don't fix it if it is working!

Posted: Mon May 29, 2006 3:23 pm
by Thalius
Whoa now you got me confused *g* !!

- ok i admit i am in mid of some strange bughunt myself -

mmhm yeah you should use #PB_Ascii. And for URI encoding ( &,? ...) are reserved.

eg:
Http://myurl.blah/<opt_file>?myvar=<uri ... ed-content>

gann.. off to customer.. maybe get some detailed answer later ..

Cheers, Thalius

Posted: Wed May 31, 2006 1:40 am
by lexvictory
code works for me, but i dont get this line: "wrk=PeekS(*bfr,i,#PB_Ascii)"
i changed the i to a -1 and it works

Posted: Wed May 31, 2006 2:21 am
by Dare
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.