Seite 2 von 2

Re: PostToHost mit Unicode-Executable

Verfasst: 05.11.2009 16:46
von MSJones
Josh hat geschrieben:ähhh, bin mir da jetzt nicht sicher wie das läuft. aber PeekS liefert dir doch einen string zurück und du brauchst sicher einen pointer. im zweifelsfall einfach probieren. ich mach das lieber auf mehrere zeilen, dann kann man fehler leichter suchen.
:-) Ich mach jaschon die ganze Zeit nix anderes als probieren.
Aber irgendwie schein ich da mit der Struktur Probleme zu haben.
Denn selbst wenn ich das PeekS rausziehe und in ne Variable schreibe, also so:

Code: Alles auswählen

          post_data.s = PeekS(@*in\post_data,Len(*in\post_data),#PB_Ascii)
          Debug post_data
          Debug @post_data
krieg ich da nur einen Buchstaben reingeschrieben.
Die Adresse von dem 1-Buchstaben String kann ich mir dann ja über @post_data holen.

Re: PostToHost mit Unicode-Executable

Verfasst: 05.11.2009 16:49
von Josh
schau noch mal mit dem externen debugger. da kannst du bei der speicheranzeige einstellen, in welchem format die daten im speicher stehn. wenn du dann da schon nix rausbekommst, dann weißt du zumindest, dass du woanders suchen musst :mrgreen:

Re: PostToHost mit Unicode-Executable

Verfasst: 05.11.2009 17:07
von ts-soft

Code: Alles auswählen

PeekS(@*in\post_data,Len(*in\post_data),#PB_Ascii)
Ist doch blödsinn, poke den String in *in\post_data als ASCII String und übergebe die Länge des ASCII Strings.

Re: PostToHost mit Unicode-Executable

Verfasst: 05.11.2009 18:07
von MSJones
So, ich glaub, jetzt hab ich's soweit, daß es funktioniert.
Die Send_HTTP_Post sieht dann bei mir so aus:

Code: Alles auswählen

Procedure Send_HTTP_Post(*in.HTTPPostStructure)
  Protected open_handle.i,connect_handle.i,request_handle.i,send_handle
  Protected result.s,headers.s
  Protected bytes_read.i,ReturnStatus.i
  Protected total_read.i  = 0   
  Protected UserAgent.s   = "IDOPOST!"     
  Protected buffer.s      = Space(1024)
 
  ;InputStructure
  ; host.s        holding the hostname Do NOT include http:// or any other protocol indicator here
  ; get_url.s     Everything after the hostname of the server
  ; result.s      Holds the result from the CGI/page
  ; post_data.s   the data that should be posted
  ; result.s      holds the reviced html

  Debug *in\get_url
  Debug *in\host
  Debug *in\post_data.s

  If *in
    open_handle = InternetOpen_(UserAgent.s,#INTERNET_OPEN_TYPE_DIRECT,"","",0)
    If open_handle
      Debug "Open_Handle: " + Str(open_handle)
     
      connect_handle = InternetConnect_(open_handle,*in\host,#INTERNET_DEFAULT_HTTP_PORT,"","",#INTERNET_SERVICE_HTTP,0,0)
      If connect_handle
        Debug "Connect_Handle: " + Str(connect_handle)
       
        request_handle = HttpOpenRequest_(connect_handle,"POST",*in\get_url,"","",0,#INTERNET_FLAG_SECURE2,0)
        If request_handle
          Debug "Request_Handle: " + Str(request_handle)
         
          post_data=AllocateMemory(Len(*in\post_data))
          PokeS (post_data,*in\post_data,Len(*in\post_data),#PB_Ascii)
          
          headers.s = "Content-Type: application/x-www-form-urlencoded"+Chr(13)+Chr(10)
          HttpAddRequestHeaders_(request_handle,@headers,Len(headers), #HTTP_ADDREQ_FLAG_REPLACE | #HTTP_ADDREQ_FLAG_ADD)
          send_handle = HttpSendRequest_(request_handle,"",0,post_data,Len(PeekS(post_data,1024,#PB_Ascii)))

          If send_handle
            Debug "Send_Handle: " + Str(send_handle)
         
            tempBuffer=AllocateMemory(bytes_read)
            
            Repeat
             
              InternetReadFile_(request_handle,@buffer,1024,@bytes_read)
              Debug Str(bytes_read)+": "+buffer
              
              If (bytes_read > 0)
                PokeS(tempBuffer,buffer,bytes_read)
                Debug "peek" +PeekS(tempBuffer,bytes_read, #PB_UTF8)
                result = result + PeekS(tempBuffer,bytes_read, #PB_Ascii)
                buffer = Space(1024)
              EndIf
             
            Until bytes_read=0
            Debug result
           
            *in\result.s = result.s
           
            ReturnStatus = #True
           
          Else
            ReturnStatus = -3
          EndIf
        Else
          ReturnStatus = -2
        EndIf
      Else
        ReturnStatus = -1
      EndIf
    Else 
      ReturnStatus = 0 
    EndIf
  Else
    ReturnStatus = 0 
  EndIf
 
  If ReturnStatus < 0 Or ReturnStatus = #True
    InternetCloseHandle_(open_handle)
  EndIf
 
  ProcedureReturn ReturnStatus
 
  ;- uncomment the following when you want To get the cookie Data - Not sure If it works Or Not.....
  ;buffer.s = Space(#MAX_PATH)
  ;headernum = 0
  ;length = Len(buffer)
  ;HttpQueryInfo_(request_handle, #HTTP_QUERY_COOKIE, @buffer, @length, @headernum)
  ;Debug buffer

EndProcedure
Vielen Dank an alle, die mir bei diesem Problem geholfen haben. Allein wär ich da verzweifelt...