1. ATK Gimmy Susan
  2. PowerBuilder
  3. Wednesday, 12 December 2018 16:57 PM UTC

Good morning GURU.

I'm playing with the SLAK messaging program and I have a problem: How can I assign the following content to a string variable?

curl -x proxy: 8081 -k -X POST -H "Content-type: application / json" --data "{'text': 'Hello I'm Gimmy!: smile:'}" https: //hooks.slack. com / services / T9F1H40UR / BEALE0WLS / BDtGXXXXXdsXXXXXXXXXXXC

It is important that the characters       "     and       '      are not altered.

If I put that command on a BAT file and i run it from dos, it works.

 

Every suggestion is welcome

 

Thank you

 

GMY

 

P.s.

Do not suggest to run a *.BAT file with the commands inside,     =)

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 12 December 2018 19:25 PM UTC
  2. PowerBuilder
  3. # Permalink

If you are going to use Run to execute a .bat file or a program, the Run function does not wait for the process to finish. To do that, use my RunAndWait object:

http://www.topwizprogramming.com/freecode_runandwait.html

Slack has an HTTP based API which you should be able to use directly instead of through curl.

Microsoft XMLHTTP COM:

http://www.topwizprogramming.com/freecode_xmlhttp.html

 

 

Comment
  1. Roland Smith
  2. Wednesday, 12 December 2018 19:43 PM UTC
  1. Helpful
  1. Roland Smith
  2. Wednesday, 12 December 2018 19:49 PM UTC
I looked at it closer and it uses OAuth for authorization. PB 2017 an OAuthClient object which should make it easier to use. I haven't used it myself so I'm not sure.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 12 December 2018 19:54 PM UTC
PB 2017 also has the HTTPClient object which would take the place of Microsoft XMLHTTP COM.
  1. Helpful
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Wednesday, 12 December 2018 17:02 PM UTC
  2. PowerBuilder
  3. # 1

Hi

Can you not just pipe the output to a file and read the file in to a string?

Cheers

David

Comment
  1. ATK Gimmy Susan
  2. Wednesday, 12 December 2018 17:29 PM UTC
Hi David.

Thanks, but your idea does not work.

i try:

1) I put the command into a db table, i read it and i run, but it does not works.

2) I run the *.bat file from Powerbuider: run ('c:\tem\xxxx.bat'), but it does not works.

3) I run it from dos command line, it works



  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 12 December 2018 17:28 PM UTC
  2. PowerBuilder
  3. # 2

Hi Gimmy;

   FWIW - I would code it ...

  • String  ls_datum
  • ls_datum  = "curl -x proxy: 8081 -k -X POST -H "
  • ls_datum  += '"Content-type: application / json"'
  • ls_datum  += " --data "
  • ls_datum  += '"{~'text': 'Hello I'm Gimmy!: smile:~'}"'
  • ls_datum  += " https: //hooks.slack. com / services / T9F1H40UR / BEALE0WLS / BDtGXXXXXdsXXXXXXXXXXXC"

HTH

Regards ... Chris

 

 

 

 

Comment
  1. ATK Gimmy Susan
  2. Thursday, 13 December 2018 11:39 AM UTC
Hi Chris.

Your solution do not work:



ls_datum += '"{~'text': 'Hello I'm Gimmy!: smile:~'}"'



is not a valid string

  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 13 December 2018 15:16 PM UTC
Please use ....



ls_datum += '"{~'text~': ~'Hello I~'m Gimmy!: smile:~'}"'
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 12 December 2018 23:40 PM UTC
  2. PowerBuilder
  3. # 3

Roland already added this in his comments but just want to make sure other readers don't miss it.  Appeon recommends to use REST Web APIs to do such integration and the new HTTPClient and OAuth objects in PowerBuilder 2017 to implement the REST calls.  The other approaches Roland mentioned are not being enhanced by Appeon so it is not prudent to rely on that.  

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 13 December 2018 14:44 PM UTC
  2. PowerBuilder
  3. # 4

I got an additional question on this in email but I don't see it here.

This code is from the RunAndWait example. Use Hide! to hide the DOS box when running a bat file.

// run the process
CHOOSE CASE is_runtype
CASE "rb_hidden"
       ll_rc = in_rwait.of_run(ls_fname, Hide!)
CASE "rb_maximized"
       ll_rc = in_rwait.of_run(ls_fname, Maximized!)
CASE "rb_minimized"
       ll_rc = in_rwait.of_run(ls_fname, Minimized!)
CASE ELSE
       ll_rc = in_rwait.of_run(ls_fname, Normal!)
END CHOOSE

 

Comment
  1. ATK Gimmy Susan
  2. Thursday, 13 December 2018 15:17 PM UTC
Hi Roland.

You are right.

I delete the message because i resolve it in this way.

I setup the value lstr_Start.wShowWindow = 0

Is it the same ?







[ omissis]

CONSTANT long STARTF_USESHOWWINDOW = 1

CONSTANT long CREATE_NEW_CONSOLE = 16

CONSTANT long NORMAL_PRIORITY_CLASS = 32

CONSTANT long INFINITE = -1

long ll_Null

string ls_Null

long ll_CreationFlags

string ls_CurDir



SetNull(ll_Null)

SetNull(ls_Null)

SetNull(ls_CurDir)



str_StartupInfo lstr_Start

str_Processinformation lstr_PI



lstr_Start.cb = 72

lstr_Start.dwFlags = STARTF_USESHOWWINDOW

lstr_Start.wShowWindow = 0



ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS



CreateProcessA(ls_Null,ls_stringa,ll_Null,ll_Null,FALSE,ll_CreationFlags,ll_Null,ls_CurDir,lstr_Start,lstr_PI)



WaitForSingleObject(lstr_PI.hProcess, INFINITE)

[ omissis]







  1. Helpful
There are no comments made yet.
ATK Gimmy Susan Accepted Answer Pending Moderation
  1. Sunday, 16 December 2018 16:19 PM UTC
  2. PowerBuilder
  3. # 5

GO ON ...

 

With the call of CURL it works, now I would like to try using a post.

What am I doing wrong ? Posturl return: -1 -- General error


-
InternetResult ls_result
inet iinet_base
blob urldata
string urlname
long ll_ret
string urlheader

urlname = "https://hooks.slack.com/services/T9F1H40UR/BEALE0WLS/BDtGxxxxxxxxxxsPLmuoBP7iC"
urldata = blob('{ "text": "Hello, world." }')
urlheader = "Content-type: application/json " + '{ "text": "Hello, world." }'

GetContextService("Internet", iinet_base)
ll_ret = iinet_base.posturl(urlname, urldata , urlheader, ls_result)
Messagebox("Return: " + string(ll_ret) ,string(ls_result))



Comment
  1. Roland Smith
  2. Wednesday, 19 December 2018 15:22 PM UTC
The PostURL function doesn't support HTTPS. If you have PB 2017, you should try the new HTTPClient object as it is supposed to support HTTPS.

Alternately I have an example of how use the Microsoft XMLHTTP COM control:

http://www.topwizprogramming.com/freecode_xmlhttp.html

Or even the HTTP API functions:

http://www.topwizprogramming.com/freecode_winhttp.html

  1. Helpful
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.