Hi All,
To add the following line to a REST Header, do I just leave the Header Name blank?
oHttp.AddHeader('', 'POST http://services.acme.com/SDP/Get HTTP/1.1')
TIA,
Steve
Hi Steve,
You don't set the URL and verb - that's not a header that's part of the request.
You need to do something like this:
loHttp = CREATE("wwHttp")
loHttp.cHttpVerb = "POST" && Not required since it's the default for posting data
*** Set content type of data you're sending
loHttp.cContentType = "application/json"
*** Set the data to send
loHttp.AddPostKey(lcJson)
lcResponse = loHttp.HttpGet(lcUrl)
IF (loHttp.Error != 0)
? loHttp.cErrorMsg
RETURN
ENDIF
*** Do something with the response
If you're calling a JSON based service, you can also look into wwJsonServiceClient which makes this even easier.
+++ Rick ---
Ok, so this is what I am being told by the vendor to use to hit the server. I also set the headers based on instructions fromm the vendor.
POST http://services.acme.com/SDP/services/Locator/Get HTTP/1.1
so do I set lcURL = "http://services.acme.com/SDP/services/Locator/Get HTTP/1.1"
and then execute: lcResponse = loHttp.HttpGet(lcUrl)
When I do this, I'm not getting the xml result I expect. I add an XML file (sample file provided by vendor) to the Post Buffer before submitting the request. I should get an XML response. Instead the response is:
lcResponse = <[]
cResultCode = 300
cResultCodeMessage = Multiple Choices
I keep thinking maybe there's something else that I need from the vendor. I have tried to follow the examples in your docs and everything works fine when I hit your server. Any thoughts?
TIA, Steve
BTW, not sure it matters, but it is an Apache web server.
lcURL = "http://services.acme.com/SDP/services/Locator/Get HTTP/1.1"
is not a valid url. Remove the HTTP/1.1
from the URL.
I think there's some basic misunderstanding on how HTTP works, so you might want to post your code.
You'll need to:
- Provide a proper URL
- Add the appropriate POST data to the request
- Make sure the appropriate HTTP headers are set
All three of those are separate things that get set individually. POST data gets set with AddPostKey()
. Headers get set with AddHeader()
, and URL is set in the call to HttpGet()
.
+++ Rick ---
Thanks Rick, yes I am using the 3 different methods, AddHeader, AddPostKey, and HttpGet.
So, when I set lcURL = "http://services.acme.com/SDP/services/Locator/Get", behind the scenes does HttpGet add the Message Request-Line as:
"POST http://services.acme.com/SDP/services/Locator/Get HTTP/1.1"
As always, Thanks!
Yes. It's an http client. You're not responsible for sending a raw http message - you just set a few properties and go.
Rick
"Thank the maker" says R2D2! 😉
Got it working! Reviewed the HTTP protocol per your suggestion. Very helpful. There were just a couple of minor things. Actually, the response was coming back, I just had to unzip it. Duh.
I currently have one other question. I am POSTing GZipped XML. Should I set nPostMode = 4 and cContentType = "application/xml"? I can leave them both out and it still works. So, a little confused on this one. I also am setting a Header of Content-Type: application/xml. Plus, the uploaded xml files are pretty small, maybe 40 lines, so is the overhead of GZip even worth it?
Thanks again, loving these tools!
Steve