Lisp HUG Maillist Archive

curl rpc with HTTP-Request or JSON-RPC

I’m a newbie at HTTP-Requests and JSON-RPC, looking for some help.  

 

I have this curl statement that works in an Apple bash shell that I’d like to be able to do on a Windows 10 PC from LispWorks 7.1.  (I’ve not been able to get this to work in a bash shell under Windows 10).

 

curl -X POST -H "Content-Type:text/plain;" -d 'RPC={"passwd":"pass","version":"1.0","proc":"GetPlantOverview","id":"1","format":"JSON"}' http://192.168.1.100/rpc

 

I’ve tried :DRAKMA, :DEXADOR and :JSONRPC with no luck:

 

(drakma:http-request "http://192.168.1.100/rpc"

                     :protocol :http/1.0

                     :method :post

                     :accept "application/json"

                     :content-type "application/text"

                     :parameters '(("passwd" . "pass")

                                   ("proc" . "GetPlantOverview")

                                   ("id" . "1")

                                  ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call.

 

 

(dex:post "http://192.168.1.100"

          :content '(("passwd" . "pass")

                     ("proc" .. "GetPlantOverview")

                     ("id" . "1")

                     ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call… somehow not unlocking the RPC mechanism in the server.

 

 

(defvar *client* (jsonrpc:make-client))

(jsonrpc:client-connect *client* :url "http://192.168.1.100:80/rpc" :mode :tcp)

 

Throws an error:

 

Error: Unable to load any of the alternatives:  ("libcrypto-1_1.dll" "libeay32.dll")

 

Looking in c:/system/windows32/ there are “libcrypo.dll” and “libcrypto-1_1-x64.dll” files.  I copied the x64 file as “libcrypto-1_1.dll” in both windows and windows32 directories… made no difference.  Can’t get jasonrpc not error out.

 

 

Would appreciate any help I can get,

Bob

 

 

Re: curl rpc with HTTP-Request or JSON-RPC

Hi,

not sure if it helps, but....

The DRAKMA example does not have the same content type of the curl command.

The jsonrpc is obviously looking to a different library.  You may want to see whether you can tell jsonrpc to use one of the different libraries.  I also presume that you need to check whether you have LW 32 or 64 bits.

All the best

Marco


On Sun, Sep 13, 2020 at 10:37 PM Bob Kirk <bobkirk888@gmail.com> wrote:

I’m a newbie at HTTP-Requests and JSON-RPC, looking for some help.  

 

I have this curl statement that works in an Apple bash shell that I’d like to be able to do on a Windows 10 PC from LispWorks 7.1.  (I’ve not been able to get this to work in a bash shell under Windows 10).

 

curl -X POST -H "Content-Type:text/plain;" -d 'RPC={"passwd":"pass","version":"1.0","proc":"GetPlantOverview","id":"1","format":"JSON"}' http://192.168.1.100/rpc

 

I’ve tried :DRAKMA, :DEXADOR and :JSONRPC with no luck:

 

(drakma:http-request "http://192.168.1.100/rpc"

                     :protocol :http/1.0

                     :method :post

                     :accept "application/json"

                     :content-type "application/text"

                     :parameters '(("passwd" . "pass")

                                   ("proc" . "GetPlantOverview")

                                   ("id" . "1")

                                  ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call.

 

 

(dex:post "http://192.168.1.100"

          :content '(("passwd" . "pass")

                     ("proc" . "GetPlantOverview")

                     ("id" . "1")

                     ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call… somehow not unlocking the RPC mechanism in the server.

 

 

(defvar *client* (jsonrpc:make-client))

(jsonrpc:client-connect *client* :url "http://192.168.1.100:80/rpc" :mode :tcp)

 

Throws an error:

 

Error: Unable to load any of the alternatives:  ("libcrypto-1_1.dll" "libeay32.dll")

 

Looking in c:/system/windows32/ there are “libcrypo.dll” and “libcrypto-1_1-x64.dll” files.  I copied the x64 file as “libcrypto-1_1.dll” in both windows and windows32 directories… made no difference.  Can’t get jasonrpc not error out.

 

 

Would appreciate any help I can get,

Bob

 

 



--
Marco Antoniotti, Associate Professor         tel. +39 - 02 64 48 79 01
DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

Re: curl rpc with HTTP-Request or JSON-RPC

Hi, to post a query with nearly the same headers as the working curl command, I’d use this with drakma:

(drakma:http-request "http://192.168.1.100/rpc"
    :method :post
    :accept "*/*"
    :content-type "text/plain;"
    :content "RPC={\"passwd\":\"pass\",\"version\":\"1.0\",\"proc\":\"GetPlantOverview\",\"id\":\"1\",\"format\":\"JSON\"}")

Note that your curl command sent a single parameter RPC, set to the JSON "property list",  while your lisp examples send passwd, version etc as parameters.
To see what headers are sent by curl, use its -v flag. 
To see the headers sent by drakma, bind drakma:*header-stream* to t, presumably an alias for *standard-output*, like this:

(let ((drakma:*header-stream* t))
  (drakma:http-request "http://192.168.1.100/rpc"
      :method :post
      :accept "*/*"
      :content-type "text/plain;"
      :content "RPC={\"passwd\":\"pass\",\"version\":\"1.0\",\"proc\":\"GetPlantOverview\",\"id\":\"1\",\"format\":\"JSON\"}")) 

Once the drakma statement returns what you’re looking for, you can refine it by checking whether the server requires the accept header, whether a content type of application/x-www-form-urlencoded is accepted, and build the json part of the payload with a json library.
Note that I used drakma because that’s what I know.  The other two approaches may be fine.
— 
chr

On 13 Sep 2020, at 23:21, Marco Antoniotti <marco.antoniotti@unimib.it> wrote:

Hi,

not sure if it helps, but....

The DRAKMA example does not have the same content type of the curl command.

The jsonrpc is obviously looking to a different library.  You may want to see whether you can tell jsonrpc to use one of the different libraries.  I also presume that you need to check whether you have LW 32 or 64 bits.

All the best

Marco


On Sun, Sep 13, 2020 at 10:37 PM Bob Kirk <bobkirk888@gmail.com> wrote:

I’m a newbie at HTTP-Requests and JSON-RPC, looking for some help.  

 

I have this curl statement that works in an Apple bash shell that I’d like to be able to do on a Windows 10 PC from LispWorks 7.1.  (I’ve not been able to get this to work in a bash shell under Windows 10).

 

curl -X POST -H "Content-Type:text/plain;" -d 'RPC={"passwd":"pass","version":"1.0","proc":"GetPlantOverview","id":"1","format":"JSON"}' http://192.168.1.100/rpc

 

I’ve tried :DRAKMA, :DEXADOR and :JSONRPC with no luck:

 

(drakma:http-request "http://192.168.1.100/rpc"

                     :protocol :http/1.0

                     :method :post

                     :accept "application/json"

                     :content-type "application/text"

                     :parameters '(("passwd" . "pass")

                                   ("proc" . "GetPlantOverview")

                                   ("id" . "1")

                                  ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call.

 

 

(dex:post "http://192.168.1.100"

          :content '(("passwd" . "pass")

                     ("proc" . "GetPlantOverview")

                     ("id" . "1")

                     ("format" . "JSON")))

 

Returns a webpage, but not the results of the RPC call… somehow not unlocking the RPC mechanism in the server.

 

 

(defvar *client* (jsonrpc:make-client))

(jsonrpc:client-connect *client* :url "http://192.168.1.100:80/rpc" :mode :tcp)

 

Throws an error:

 

Error: Unable to load any of the alternatives:  ("libcrypto-1_1.dll" "libeay32.dll")

 

Looking in c:/system/windows32/ there are “libcrypo.dll” and “libcrypto-1_1-x64.dll” files.  I copied the x64 file as “libcrypto-1_1.dll” in both windows and windows32 directories… made no difference.  Can’t get jasonrpc not error out.

 

 

Would appreciate any help I can get,

Bob

 

 



--
Marco Antoniotti, Associate Professor         tel. +39 - 02 64 48 79 01
DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

Updated at: 2020-12-10 08:28 UTC