Title: Restfull doTextRequest Post by: Nuno T. 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. Title: Re: Restfull doTextRequest Post by: Moriah W. 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 (https://tunnelrush3.com) 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. Title: Re: Restfull doTextRequest Post by: william s. on February 23, 2024, 03:29:39 am Hello, 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.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 (https://geometrygame.io/) " ) 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. 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. Title: Re: Restfull doTextRequest Post by: fada b. 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. I understand, thank you very much.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 (https://backroomsgame.io) ```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. |