2

I'm trying to use the following tcl script to login into betfair non-interactively:-

#!/usr/bin/env tclsh
package require TclCurl

set postData "username=xxxxxxxxx&password=yyyyyyyyy"
set postHeader [list "X-Application: curlCommandLineTest"]
set BFLogin [::curl::transfer -url https://identitysso-cert.betfair.com/api/certlogin \
-headervar loginHeader \
-sslverifypeer 0 \
-sslcert "client-2048.crt" \
-sslkey "client-2048.key" \
-post 1 \
-postfields $postData \
-httpheader $postHeader ]

However, it's not storing the output in BFLogin. Instead when the script finishes it just outputs something like:-

{"sessionToken":"92YN1v2Oz0lVv59nHwCryrfCnzNbInTCsssssssssssssssssss","loginStatus":"SUCCESS"}

Which is fine but it's not storing it in the variable BFLogin above. What am I doing wrong please?

mrcalvin
  • 3,291
  • 12
  • 18
user1062524
  • 63
  • 1
  • 5

2 Answers2

2

From what I gathered from this manual and the wiki, it seems like you can use the option -bodyvar to tell curl where to store the body response (the call response and the body response are separate). I cannot test the code, but it should probably work like that:

#!/usr/bin/env tclsh
package require TclCurl

set postData "username=xxxxxxxxx&password=yyyyyyyyy"
set postHeader [list "X-Application: curlCommandLineTest"]
set responseBody ""
set BFLogin [::curl::transfer -url https://identitysso-cert.betfair.com/api/certlogin \
    -bodyvar responseBody \
    -sslverifypeer 0 \
    -sslcert "client-2048.crt" \
    -sslkey "client-2048.key" \
    -post 1 \
    -postfields $postData \
    -httpheader $postHeader ]

I also removed the headervar option you had, since it doesn't look like you were using it

Jerry
  • 70,495
  • 13
  • 100
  • 144
1

Possibly more readable?

#!/usr/bin/env tclsh
package require TclCurl

dict set curlOpts -url https://identitysso-cert.betfair.com/api/certlogin
dict set curlOpts -bodyvar responseBody
dict set curlOpts -sslverifypeer 0
dict set curlOpts -sslcert "client-2048.crt"
dict set curlOpts -sslkey "client-2048.key"
dict set curlOpts -post 1
dict set curlOpts -postfields "username=xxxxxxxxx&password=yyyyyyyyy"
dict set curlOpts -httpheader [list "X-Application: curlCommandLineTest"]

curl::transfer {*}$curlOpts
glenn jackman
  • 238,783
  • 38
  • 220
  • 352