1. Desarrolladores appeon 4
  2. PowerBuilder
  3. Thursday, 15 February 2024 17:49 PM UTC

Hi

 

I want to consume a REST service sending the JSON format and get a response from the service.

 

I get the TOKEN using GetJWTToken, which works fine and it is valid, but when I consume the REST service it's require, it returns an error that tells the following:

 

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00- 9b842ef37383feb036f413cd6560d311-c8b3cffffab8c86b-00"}

 

In a simple google search of this 415 error on the site https://tools.ietf.org/html/rfc7231#section-6.5.13; indicates the following:

 

"6.5.13. 415 Unsupported Media Type

 

    The 415 (Unsupported Media Type) status code indicates that the

    origin server is refusing to service the request because the payload

    is in a format not supported by this method on the target resource.

    The format problem might be due to the request's indicated

    Content-Type or Content-Encoding, or as a result of inspecting the

    data directly."

 

The procedure (code) I am doing the call of the service is the following:

"

li__P020_SendReturn = irc_json_envio.SendPostRequest("https://ea1-test.apis.sietesdata.com/api/Sietes/SendJson", ls_PostData, ls_P020_Responsebody)

If li__P020_SendReturn <> 1 Or irc_json_envio.GetResponseStatusCode() <> 201 Then

    //Checks if any error information

ll_response = irc_json_submission.GetResponseStatusCode()

ls_StatusText = irc_json_envio.GetResponseStatusText()

messagebox( ' of_json_envio_test fails ' , 'irc_json_envio.GetResponseStatusCode() ' + String( irc_json_envio.GetResponseStatusCode() ) + ' ' + ls_StatusText + '~r~n~r~nls_P020_Responsebody ' + ls_P020_Responsebody )

 

Else

 

messagebox( ' of_json_test_submission ' , 'ls_P020_Responsebody ~r~n' + String( ls_P020_Responsebody ) )

as_response = ls_P020_Responsebody

ll_response = irc_json_submission.GetResponseStatusCode()

End If

 

messageBox( ' of_json_test_sending - Output' , ' li__P020_SendReturn ' + String( li__P020_SendReturn) )

messageBox( ' of_json_test_submission - Output - ls_P020_Responsebody ' , ls_P020_Responsebody )

 

"

We have been used POSTMAN to verify the JSON sending test and the results have been accurate.

 

So, I want to kwon if I did something incorrect using these functions or I have to considerate anything  else.

Thanks in advance.

Best Regards.

Kevin Ridley Accepted Answer Pending Moderation
  1. Thursday, 15 February 2024 20:26 PM UTC
  2. PowerBuilder
  3. # 1

Usually Postman will give you everything you need between the Authorization, Headers and Body tabs.  You can also use a tool like Fiddler to trap the full request so you can duplicate it with the HTTPClient.

Comment
There are no comments made yet.
Desarrolladores appeon 4 Accepted Answer Pending Moderation
  1. Thursday, 15 February 2024 19:41 PM UTC
  2. PowerBuilder
  3. # 2

Thanks, I am going to try out it. 

Comment
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Thursday, 15 February 2024 18:04 PM UTC
  2. PowerBuilder
  3. # 3

I haven't used the REST Client extensively, but one of the things I would try is setting the Content-Type header of the request indicating that the payload is a JSON string (application/json). I believe Postman sets this automatically.

You might also need to set the Content-Length header, I'm not sure how much the REST Client object will automatically do for you when setting the content.

https://docs.appeon.com/pb2022/powerscript_reference/setRequestHeader_func.html

Regards,
Francisco

Comment
  1. Logan Liu @Appeon
  2. Tuesday, 20 February 2024 10:33 AM UTC
E.g.: irc_json_envio.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
  1. Helpful 2
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.