Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Restfull doTextRequest  (Read 5340 times)
Nuno T.
Posts: 14


« on: September 28, 2023, 05:07:05 pm »

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" )
        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.
Moriah W.
Posts: 1


« Reply #1 on: January 24, 2024, 05:13:25 am »

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"}
tunnel rush
LET req = com.HttpRequest.Create("https://xxx/GetProductAvailabilities" )
        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 that you are getting might be caused by the fact that you are trying to send a JSON request body with a GET method. Some possible solutions that you can try are:

  Change the GET method to POST method in your code, and check if the web service accepts the POST method and the JSON request body. You said that it works, but it is not allowed.

  Keep the GET method, but remove the JSON request body and the Content-Type header from your code. Instead, append the JSON data as query parameters to the request URL, and encode them properly.

  Use a different class or library that supports sending JSON data with the GET method.
william s.
Posts: 2


« Reply #2 on: February 23, 2024, 03:29:39 am »

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.
fada b.
Posts: 1


« Reply #3 on: March 12, 2024, 10:44:14 am »

Quote
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:
backrooms game

```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.
I understand, thank you very much.
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines