FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour HTTP Post
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
HTTP Post
Posted: Wed Mar 07, 2012 05:04 PM

Hello,

Can someone provide an example of how to perform http post from FWH. I need to be able to post XML message and handle the response from a remote server.

I appreciate your assistance.

Sincerely,

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: HTTP Post
Posted: Wed Mar 07, 2012 05:19 PM
Best regards,
Otto

Code (fw): Select all Collapse
Function testXML()
        local loHyperlink := TOLEAuto():New( "Microsoft.XmlHttp" ) 
    local cXML
    local cURL
   
        cXML := "<request><username>USERXYZ</username><password>PWXYZ</password><room id='999'><date value='2012-04-15'></rate></room></request>"
        cURL := "https://test.com/hotels/xml/availability"
   
    loHyperlink:Open( "POST", cURL, .f. ) 
   
    loHyperlink:setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        
    cxml := "xml=" + cxml
   
        loHyperlink:Send(cXML )
    
    
    if (At( "SUCCESS", upper(loHyperlink:responseText )) < 5)
        msginfo("responseText" + CRLF + loHyperlink:responseText)
    else
        msginfo("Senden war erfolgreich")
    endif
    

return nil 
//----------------------------------------------------------------------------//
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: HTTP Post
Posted: Wed Mar 07, 2012 06:32 PM

Thank you Otto!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: HTTP Post
Posted: Mon Apr 16, 2012 03:30 PM

Dear Otto,

I have created the following code, however I am not get getting the response from the destination. Can you tell me what I am doing wrong?

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function _XmlPost()

local loHyperlink := TOLEAuto():New( "Microsoft.XmlHttp" )
local cXML
local cURL
local cCreate := ""

// Init...
cCreate := LEFT( DTOS( DATE() ), 4 ) + "-" + SUBSTR( DTOS( DATE() ), 5, 2 ) + "-" + RIGHT( DTOS( DATE() ), 2 ) + "T" + TIME() + ".0Z"
cEvent := DTOS( CTOD( "04/10/2012" ) )
cTime := "11:06:53"
cOffset := "-06:00"
cBiz1 := "0614141"
cPo := "987654321"

cXml := [<?xml version="1.0" encoding="UTF-8" standalone="yes"?>]
cXml += [<epcis:EPCISDocument ]
cXml += [xmlns:epcis="urn:epcglobal:epcis:xsd:1" ]
cXml += [xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ]
cXml += [creationDate="] + cCreate + [" ]
cXml += [schemaVersion="1">]

cXml += [<EPCISBody>]
cXml += [<EventList>]
cXml += [<TransactionEvent>]

cXml += [<eventTime>]
cXml += LEFT( cEvent, 4 ) + "-" + SUBSTR(cEvent,5,2) + "-" + RIGHT( cEvent, 2 )
cXml += "T"
cXml += cTime
cXml += cOffset
cXml += [</eventTime>]

cXml += [<eventTimeZoneOffset>]
cXml += cOffset
cXml += [</eventTimeZoneOffset>]

cXml += [<bizTransactionList>]

cXml += [<bizTransaction]
cXml += [ type="urn:epcglobal:demo:btt:po">]
cXml += [urn:epcglobal:demo:bti:po:] + cBiz1 + "." + cPo
cXml += [</bizTransaction>]

cXml += [</bizTransactionList>]

cXml += [<epcList>]
FOR nX1=1 TO 6
cXml += [<epc>]
cXml += [urn:epc:id:giai:] + cBiz1 + "." + STR(nX1,1)
cXml += [</epc>]
NEXT nX1
cXml += [</epcList>]

cXml += [<action>]
cXml += [ADD]
cXml += [</action>]

cXml += [</TransactionEvent>]
cXml += [</EventList>]

cXml += [</EPCISBody>]
cXml += [</epcis:EPCISDocument>]

// temp...
hHan = FCREATE( cBiz1 + ".XML", 0 )
IF (hHan == -1)
MsgWait( "Error Creating " + cBiz1 + ".XML", Ptitle, 1 )
ELSE
FWRITE( hHan, cXml )
FCLOSE( hHan )
MsgWait( cBiz1 + ".XML Created", Ptitle, 1 )
ENDIF

cURL := "http://epcis.allumis.com:8080/epcis-repository-0.5.0/capture"
//cURL := "http://199.188.244.226:8080/epcis-repository-0.5.0/capture"

TRY

 loHyperlink:Open( &quot;POST&quot;, cURL, .f. )

 loHyperlink:setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;)

 cxml := &quot;xml=&quot; + cxml

 loHyperlink:Send(cXML )

CATCH
MsgAlert( "Error Transmitting XML", Ptitle )
END

if (At( "SUCCESS", upper(loHyperlink:responseText )) < 5)
MsgWait( cUrl + cEol + "XML Response = " + CRLF + loHyperlink:responseText, Ptitle, 5)

 USE epcis
 APPEND BLANK
 epcis-&gt;response     := UPPER( loHyperlink:responseText )
 epcis-&gt;date         := DATE()
 epcis-&gt;time         := TIME()

else
MsgWait( Cutl + cEol + "Error", Ptitle, 10 )
endif
DbCloseAll()

RETURN (.T.)

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: HTTP Post
Posted: Mon Apr 16, 2012 04:10 PM

Dear Otto,

I found the problem related to content type which should be "text/xml"

Besides the text response, there is a response code. How do I capture the response code?

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: HTTP Post
Posted: Mon Apr 16, 2012 05:03 PM

Dear Otto,

I was able to locate XML HTTP Properties and resolved problem.

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: HTTP Post
Posted: Mon Apr 16, 2012 05:14 PM

Hello Darrell,
good to hear that it works for you.
Best regards,
Otto

Continue the discussion