Code: Select all | Expand
function Main() local odoc := CreateObject( "MSXML2.DOMDocument" ) local ohttp := CreateObject( "MSXML2.XMLHTTP" ) local strret ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. ) ohttp:SetRequestHeader( "Accept" , "application/xml") ohttp:SetRequestHeader( "Content-Type" ,"application/json" ) oDoc:async := .f. oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>') ohttp:Send(oDoc:xml) strret := alltrim(ohttp:responseText) ? strret StrToHashArray( StrRet )return nilfunction StrToHashArray( cStr ) local hHash, aHash cStr := CharRepl( "[]", RangeRem( 1, 31, cStr ), "{}" ) do while '" :' $ cStr StrTran( cStr, '" :', '":' ) enddo cStr := StrTran( cStr, '":', '"=>' ) hHash := &cStr aHash := HGetValueAt( hHash, 1 ) xbrowser aHash setup ( obrw:autofit(), oBrw:bRClicked := { |r,c,f,o| o:ToDbf( "download.dbf", nil, nil, .t. ) } )return nil
My problem is a bit different. I need to send a request to a defined website, and then read the result.
The sending statement is in the format:
Code: Select all | Expand
oHttp:=TIpClientHttp():new("https://testserver.com/data/1", .F. )cJson := '{"partid":"147A964","productDataid":"PR123","locationid":"10000"}'cRet := ""IF .NOT. oHttp:open() MsgAlert( "Connection error:", oHttp:lastErrorMessage( ) )ELSE oHttp:Post( cJson) cRet := oHttp:readAll( ) oHttp:close()ENDIF nFileHandle := FCreate( "retdata.txt" ) FWrite( nFileHandle, cRet ) FClose( nFileHandle )
And the response should be a JSON string. However, I get no data back. I'll worry about parsing the data when I get a return string, but at this point, it appears JSON may not like the TIP Harbour control. With the example posted on JSON decoding previously, the approach was a bit different. I'd appreciate it if someone has some alternative approaches on how I should be handling this request / response sequence.
Thanks so much.
Tim
For XML data I have been using