1. Johann Lessmann
  2. PowerBuilder
  3. Tuesday, 6 November 2018 15:24 PM UTC

Hi,

I don't know how to send JSON-arguments to a RESTfull webservice with PB2017R3 ...

That is the whole "documentation" that I've got:

URL: http://12.34.56.78/blabla.php
HEADER: "Content-Type: application/json"
POST-Data in JSON-format: 
{  "_METHOD":"GET",  "user":"blabla", "company":"blabla3",  "branch":"blabla4" }

Any hint is welcome… :-)

Johann

Accepted Answer
Juan Alejandro Lam López Accepted Answer Pending Moderation
  1. Tuesday, 6 November 2018 16:58 PM UTC
  2. PowerBuilder
  3. # Permalink

You must use the HttpClient object in the following way

HttpClient inv_httpClient
INTEGER li_return, li_status_code
String ls_url, ls_json, ls_returndata

ls_url = "http://12.34.56.78/blabla.php"
ls_json = '{"user":"blabla", "company":"blabla3", "branch":"blabla4" }'

inv_HTTPClient = CREATE HTTPClient

inv_HttpClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")

li_return = inv_HttpClient.SendRequest("POST", ls_url, ls_json)

li_status_code = inv_HttpClient.GetResponseStatusCode()

IF ai_return < 0 THEN
// ERROR
END IF
IF li_status_code <> 200 THEN
//If the Status Code from the Web Service is different from "OK"
//Notify the user of the Error Message
MessageBox("Send Request", String(li_status_code) + ": "+ String(ahc_httpclient.GetResponseStatusText()))
END IF

li_return = inv_HttpClient.GetResponseBody(ls_returndata, EncodingUTF8!)


IF li_return = -1 THEN
//Notify the User of the Error
MessageBox("Post JSON", "Get response body failed.")
//Return Failure!
RETURN
END IF

RETURN ls_returndata

Comment
There are no comments made yet.
Johann Lessmann Accepted Answer Pending Moderation
  1. Wednesday, 7 November 2018 12:55 PM UTC
  2. PowerBuilder
  3. # 1

Thank you very much Juan Alejandro! 

Comment
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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.