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)
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 ---
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.
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 ---