TipClientHttp POST data how to

658 views
Skip to first unread message

clipper6

unread,
Jan 7, 2015, 8:01:05 PM1/7/15
to harbou...@googlegroups.com
Hi,

I want to POST data to a URL. The code fragment below shows how it is done using GET. Can someone be kind enough to give an example on how it is done using POST.
 
    // httpadv.prg @ \hb32\contrib\hbtip\tests
    ...
    IF oCon:Get( oUrl:cPath )
         ? "Get Sucessful"
         FOR i := 1 TO Len( oCon:hHeaders )
            ? hb_HKeyAt( oCon:hHeaders, i ) + ":", hb_HValueAt( oCon:hHeaders, i )
         NEXT
      ELSE
         ? "Get failure (server reply:", oCon:cReply, ")"
      ENDIF
      ...
I want to submit this data to a URL: id=1234, lastname=smith, firstname=john. I also like to store the returned value to a variable.

Message has been deleted

clipper6

unread,
Jan 8, 2015, 10:22:38 PM1/8/15
to harbou...@googlegroups.com
Out of desperation since I don't know the parameters/syntax of post in harbour what I did was generate a page containing a javascript that passes all the parameters to a url. It's not elegant but that should do for now.

Lorenzo Fiorini

unread,
Jan 9, 2015, 12:45:39 AM1/9/15
to harbou...@googlegroups.com
On Fri, Jan 9, 2015 at 4:22 AM, clipper6 <arl...@gmail.com> wrote:

> Out of desperation since I don't know the parameters/syntax of post in
> harbour what I did was generate a page containing a javascript that passes
> all the parameters to a url. It's not elegant but that should do for now.

The simplest way is to pass an hash. Try this:

function main()
local cUrl := "http://yoururl"
local hFields := {=>}
local cRetBuf

local oURL
local oClient

hFields[ "id1" ] := "data1"
hFields[ "id2" ] := "data2""

oURL := tURL():New( cUrl )

oClient := TIpClientHttp():new( oUrl )

oClient:nConnTimeout := 2000

if oClient:Open()

qout( "Open", oClient:lastErrorMessage() )

oClient:Post( hFields )

qout( "Post", oClient:lastErrorMessage() )

cRetBuf := oClient:Read()

qout( "Read", oClient:lastErrorMessage() )

endif

oClient:Close()

qout( "Close", oClient:lastErrorMessage() )

qout( hJson )

return nil

best regards,
Lorenzo

clipper6

unread,
Jan 12, 2015, 1:55:54 AM1/12/15
to harbou...@googlegroups.com
Thanks. I'll try this.

clipper6

unread,
Jan 12, 2015, 2:25:59 AM1/12/15
to harbou...@googlegroups.com
Where can I find the documentation on how to use TIpClientHttp?


On Friday, January 9, 2015 at 1:45:39 PM UTC+8, LF wrote:

Karsten Stücker

unread,
Jan 16, 2015, 5:07:44 AM1/16/15
to harbou...@googlegroups.com
hey clipper6,
there is no real documentation,
i think you have to look into the source of httpcli.prg, or the examples, or ask here.

clipper6

unread,
Jan 19, 2015, 10:00:55 PM1/19/15
to harbou...@googlegroups.com
Yes I always come here to ask questions and I thank everyone for answering my questions.
Reply all
Reply to author
Forward
0 new messages