West Wind Internet and Client Tools
Handling HTML result from POST
Gravatar is a globally recognized avatar based on your email address. Handling HTML result from POST
  Tamar E. Granor
  All
  Nov 22, 2022 @ 12:29pm

A client has asked me to add integration with a 3rd party service to an existing VFP application. The 3rd party service operates a sales website and has provided an SDK for communicating with the site.

I'm testing using wwIPStuff in between VFP and the site. The SDK operates from POSTs and the first call I tried worked just as I'd hoped and gave me a JSON result that I can parse and work with.

But the main thing I need to do is call on this site to actually display a subset of products and let the user shop. When I POST the call to start that process, what I get back is HTML with JavaScript.

I'm trying to figure out what to do with that result. I tried saving it as a file and and using Navigate2 in a WebBrowser control, but I get script errors and nothing appears in the control.

I've never done anything like this before and I feel like I'm missing a key piece of the equation.

Thanks Tamar

Gravatar is a globally recognized avatar based on your email address. re: Handling HTML result from POST
  Rick Strahl
  Tamar E. Granor
  Nov 23, 2022 @ 12:24pm

Make sure the HTTP endpoint (Url) you are hitting is actually an API endpoint that returns JSON. If that's not it find the documentation and look closely at what the service is asking for input.

A few things that come to mind:

  • Make sure if you post data to the service you set the Content-Type (json is application-json)
  • Do you need authentication? The HTML you see may be their login page because you're not authenticated.
  • Do you need to pass some sort of Auth token?

When working with API endpoints I always recommend you test it outside of code first. You can use a tool like:

To hit the URL with the data and tweak it interactively with these tools until you get it working there. This removes the code angle from the HTTP request and lets you look at raw data that is sent and you then duplicate with the FoxPro code.

If you're new to all this I recommend you take a look at my Virtual FoxFest session and white paper from last year:

The first section is an introduction on the HTTP aspects you're asking about here, and the second part walks through how to call JSON APIs sending and retrieving data.

Hope this helps,

+++ Rick ---

© 1996-2022