Hello,
I need to do a Restful request to a outside web service, is there a way to use method GET and a json request ?
LET json = {"articleNumber":"800700"}
LET req = com.HttpRequest.Create("
https://xxx/GetProductAvailabilities geometry dash " )
CALL req.setMethod("GET")
CALL req.setHeader("Content-Type", "application/json")
CALL req.setHeader("Accept", "application/json")
CALL req.doTextRequest(json)
I always have this error message:
Program stopped at 'codetest.4gl', line number 63.
FORMS statement error number -15555.
Unsupported request-response feature.
If i change to POST, it works, but it is now allowed.
Thanks very much in advance.
The error message you're seeing means that the functionality you're attempting to utilize (sending a JSON payload in a GET request) isn't supported. According to RESTful principles, JSON payloads are often supplied using POST requests rather than GET requests.
If you need to deliver a JSON payload in a GET request, encode the data as query parameters in the URL. Here's an example of how to change your code to accomplish this:
```python
import com.HttpRequest
LET json = {"articleNumber":"800700"}
LET json_string = STRING(json)
LET encoded_json = com.HttpUtility.urlEncode(json_string)
LET url = "
https://xxx/GetProductAvailabilities?data=" + encoded_json
LET req = com.HttpRequest.Create(url)
CALL req.setMethod("GET")
CALL req.setHeader("Content-Type", "application/json")
CALL req.setHeader("Accept", "application/json")
CALL req.doTextRequest("")
```
In this code sample, the JSON data is first encoded with the 'com.HttpUtility.urlEncode()' method before being attached to the URL as a query parameter. This allows you to include JSON data in your GET request.
Please keep in mind that encoding sensitive information or big payloads in URLs is not recommended due to security and performance concerns. Consider transmitting JSON payloads via POST requests whenever possible.