HTTP Post

HTTP Post

Postby cdmmaui » Wed Mar 07, 2012 5: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: HTTP Post

Postby Otto » Wed Mar 07, 2012 5:19 pm

Best regards,
Otto

Code: Select all  Expand view
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
//----------------------------------------------------------------------------//

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: HTTP Post

Postby cdmmaui » Wed Mar 07, 2012 6:32 pm

Thank you Otto!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: HTTP Post

Postby cdmmaui » Mon Apr 16, 2012 3: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( "POST", cURL, .f. )

loHyperlink:setRequestHeader("Content-Type", "application/x-www-form-urlencoded")

cxml := "xml=" + 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->response := UPPER( loHyperlink:responseText )
epcis->date := DATE()
epcis->time := TIME()
else
MsgWait( Cutl + cEol + "Error", Ptitle, 10 )
endif
DbCloseAll()

RETURN (.T.)
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: HTTP Post

Postby cdmmaui » Mon Apr 16, 2012 4: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: HTTP Post

Postby cdmmaui » Mon Apr 16, 2012 5: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: HTTP Post

Postby Otto » Mon Apr 16, 2012 5:14 pm

Hello Darrell,
good to hear that it works for you.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests