West Wind Internet and Client Tools
REST Header Question
Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Rick Strahl
  Steve
  Jun 3, 2017 @ 08:19pm

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

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Steve
  Rick Strahl
  Jun 4, 2017 @ 07:45pm

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

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Steve
  Rick Strahl
  Jun 4, 2017 @ 07:53pm

BTW, not sure it matters, but it is an Apache web server.

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Rick Strahl
  Steve
  Jun 5, 2017 @ 01:19am
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 ---

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Steve
  Rick Strahl
  Jun 5, 2017 @ 05:05am

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!

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Rick Strahl
  Steve
  Jun 5, 2017 @ 12:13pm

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

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Steve
  Rick Strahl
  Jun 6, 2017 @ 06:59am

"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

Gravatar is a globally recognized avatar based on your email address. re: REST Header Question
  Rick Strahl
  Steve
  Jun 6, 2017 @ 09:28am

Don't gzip your request - it's rarely worth it. If you do the encoding has to be changed in the request.

Wwhttp can automatically unpack gzipped content. Check for lUseGzip or something like that.

Rick

© 1996-2024