I followed the examples and added an http header object prior to calling the service. However, the call always creates a new (blank) header.
Any idea what might be wrong?
George ...
Code please?
+++ Rick ---
Certainly:-)
do wwhttp
do wwJsonSerializer
oProxy = CREATEOBJECT("wwJsonServiceClient")
loHttp= CREATEOBJECT("wwHttp")
loHttp.AddHeader("George","Smart" )
*** Pass it to the proxy to use
oProxy.CreatewwHttp(loHttp)
*** Make the service call
logetdata = oProxy.CallService("https://arglobal.sugarondemand.com/rest/v11/"+"Opportunities/9be25aa4-6762-11e9-9226-069e4f790264/audit","","GET")
Please - use the formatting tools to format your code. You can edit and fix your message...
Thanks,
+++ Rick ---
Sorry, this is Much prettier now. This example is a little different from the first iteration I tried using (also taken from the documentation and tweaked). Neither worked. For now I modified the class itself (just a little) to make it work. But I would much prefer to know what I am doing wrong. It just seems that the HTTP object gets recreated by the call - no matter what.
Thanks
George
I tried this and it works for me.
How are you checking for the header? The header is an HTTP Header meaning you can't see it unless you use an HTTP proxy to look at the raw traffic.
+++ Rick ---
That is strange then.
I used FIDDLER to get to where I understood why the Authentication token wasnt working. In the code I pasted I found that the EXTRA header values simply do not show up under "Miscellaneous". My mod to the class involved testing for the ohttp object inside the callservice. This worked, but I am not inclined to think I know better than you and would rather not touch your code (that is such a bad idea for many reasons).
George
Should I upgrade to V7.04? I am still on V6 today.
Not sure what you're saying. Your sample isn't passing an Authorization
. To pass a bearer token use (with plain wwHttp but same thing really):
loHttp = CREATEOBJECT("wwHttp")
loHttp.AppendHeader("x-custom","Custom Header")
loHttp.AppendHeader("Authorization","Bearer x321cadsadsasdadssad")
loHttp.Get("http://localhost/wconnect/Testpage.wwd")
This gets you:
Which you can retreive on the server with:
lcToken = STRTRAN(Request.ServerVariables("HTTP_AUTHORIZATION"),"Bearer ", "")
+++ Rick ---
Thanks Rick, I hope I am not confusing matters too much.
In fiddler with the code I sent you I do not see any additional headers.
However, after I have modified the callservice part of the wwjsonserializer class like this:
FUNCTION CallService(lcUrl,lvPostData, lcVerb)
LOCAL lcResult, lcJson, loHttp, loSer, loResult
this.lError = .F.
IF EMPTY(lcVerb)
IF IsNullOrEmpty(lvPostData)
lcVerb = "GET"
ELSE
lcVerb = "POST"
ENDIF
ENDIF
If Vartype(This.oHttp) <> "O"
loHttp = This.CreatewwHttp()
Else
loHttp = This.oHttp
Endif
loHttp.cHttpVerb = lcVerb
Everything works just fine for me, and my API call succeeds.
GET https://arglobal.sugarondemand.com/rest/v11/Opportunities/9be25aa4-6762-11e9-9226-069e4f790264/audit HTTP/1.1
OAuth_Token: ece4deec-87a9-4a6c-ae8b-7e6a53b4f0f4
User-Agent: West Wind Internet Protocols 6.10
Host: arglobal.sugarondemand.com
Cache-Control: no-cache
Cookie: PHPSESSID=ece4deec-87a9-4a6c-ae8b-7e6a53b4f0f4; download_token_base=85680e69-eabd-4652-b05d-e4a06f84284a; AWSELB=C1BFF3F1185A598E31599FD0CAE26FCCC1539D82734A9226DEB2B17C2B6BDD5FDF11902B7F0EBD756F928CEEC99F87365ABC022024606885E4CBBC92063205185DF6445B86
You might have an older version. There were a number of small issues with original release of the Json Service client that have been fixed since. The first examples I ran I used the service client (in 7.0) and it most definitely works there.
So looks like you fixed this. Upgrading to a more recent version is often a good idea to make sure you get all the latest fixes and updates etc. but that's up to you to decide.
Hope this helps,
+++ Rick ---
Thanks Rick,
I just placed an upgrade order on your website "297b91b2".
There isnt anyone here to place a proper order, so I just used my Personal Credit card. We have a few licenses here which Mark used to manage for us, but he has left now. I will ask Warren to upgrade the rest next week.
Thanks for your help last night and this morning. Much appreciated.
George ...
Quick follow up for anyone interested. This issue is completely resolved in the current version of WebConnecton. I am sure there are many other good reasons to upgrade also, but this is a good reason to stay up to date.
Yes it's a good idea to keep up to date for sure...
JsonServiceClient
is a newish class that was introduced late in the 6.x cycle so when it originally shipped it in 6.0 it wasn't officially supported (or mentioned) - it wasn't actually added officially until 7.0 came out so that's part of the reason. But even since then there have been some improvements including a small improvement I made during this discussion which will go out in the next release.
+++ Rick ---