West Wind Internet and Client Tools
HttpGet result is an array that VFP can't seem to read.
Gravatar is a globally recognized avatar based on your email address. HttpGet result is an array that VFP can't seem to read.
  Keith Hebert
  All
  Nov 16, 2021 @ 07:26am

When sending httpget requests normal requests return json string object not problem. All errors are returned in an array that VFP can't seem to read or open. DeserializeJson returns errors. (OLE IDispatch exception code 0 from Newtonsoft.JSONUnexpected Character encountered while parsing value: . Path'', line 0, position 0...)

Is there a way to get or request json string or read raw data? Not sure what to do with this. Any help is appreciated.

Thanks

Code:

http_Verb = "POST"
loHTTP = createobject("wwHTTP")
loHttp.cContentType = "application/json"

lcJSON = lcJsonIn
http_Verb = "POST"	
loSer1 = CREATEOBJECT("wwJsonSerializer")
lcJsonIn = loSer1.Serialize(lcJSON)


lcGuid = get_guid()

loHTTP.AddHeader("authorization","Bearer "+ALLTRIM(thisform.otoken))
loHTTP.AddHeader("content-type","application/json")
loHTTP.AddHeader("x-locale","en_US")
loHTTP.AddHeader("x-customer-transaction-id ",+'"'+lcGuid+'"')

loHttp.AddPostKey(lcJsonIn)
lcResult = loHTTP.HttpGet(&lcUrl)


lcReturn = loSer1.DeserializeJson(lcResult)
Gravatar is a globally recognized avatar based on your email address. re: HttpGet result is an array that VFP can't seem to read.
  Rick Strahl
  Keith Hebert
  Nov 16, 2021 @ 11:01am

The result data has to be JSON. If it's something else you can't deserialize it.

You need to probably check for errors both on the connection (loHttp.nError) as well as check Http Result codes, or you can check the string for starting with { for an object, or [ for an array which tends to be a quick way to check for common JSON results.

Here are some of the things that are useful:

? loHttp.nError          && HTTP or Protocol Error
? loHttp.cResultCode     && Http Status Code
? loHttp.cHttpHeaders    && All the headers (useful for debugging)
? loHttp.GetHttpHeader("Content-Type")   && Retrieve a single header

Putting it together at minimal level:

LOCAL loHttp as wwHttp
loHttp = CREATEOBJECT("wwHttp")
lcHtml = loHttp.Get("https://west-wind.com/wconnect/testpage.wwd")
if (loHttp.nError # 0)
   ? loHttp.cErrorMsg
   RETURN 
ENDIF

if loHttp.cResultCode # "200"
   ? loHttp.cErrorMsg
   RETURN
endif

If the content is not JSON you need to figure out what to do with it, but you should know what you're expecting - whether it's JSON, HTML, or a binary download of a file.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HttpGet result is an array that VFP can't seem to read.
  Keith Hebert
  Keith Hebert
  Nov 22, 2021 @ 11:20am

I don't know what the data is but the Fedex support team says it is JSON. But this is the response I get. This is also what is in RAW tab of Fiddler Everywhere. This is intentional error by sending expired token for authorization. If i send good token and make no then changes then everything is fine.

Gravatar is a globally recognized avatar based on your email address. re: HttpGet result is an array that VFP can't seem to read.
  Rick Strahl
  Keith Hebert
  Nov 22, 2021 @ 10:05pm

Probably GZip/Deflate encoded. In Fiddler you can decode the response and if that works it's Gzip encoding.

In wwHttp set lAllowGzip = .T. to automatically decode GZip/Deflate content.

Alternately make sure you're not requesting GZip/Deflate content via the Accept-Encoding header. If that's not set the server should not return compressed data.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HttpGet result is an array that VFP can't seem to read.
  Keith Hebert
  Rick Strahl
  Nov 23, 2021 @ 05:22am

Thank You Rick. That was the problem. It works fine now.

© 1996-2021