POST http send not working as expected

16 views
Skip to first unread message

Daniel Howarth

unread,
Apr 23, 2024, 2:51:31 AM4/23/24
to GAMA
I followed this question to try to send HTTP requests: https://groups.google.com/g/gama-platform/c/EMugXKTsEYY/m/BZ0ZqIQcAgAJ

The following code works, but when I change the contents of the send method to a map like in email chain, e.g.

 ["POST",["a"::1], ["Content-Type"::"application/json"] ];

I get an error saying a map cannot be converted to a string, pasted at the bottom. 

model test
global {
init {
           create radio number: 1;
}
}
species radio skills: [network]{
int msgSent;
init {
}
reflex fetch when: (msgSent = 0) {
do connect to: "http://localhost" protocol: "http" port: 10000  with_name: "server0" ;
do send to:"/wrangler/v1.0/fit" contents:  ["POST",'{"data": {"target": {"target": [3, 4, 5]}, "covariates": {"a": [2, 3, 4], "b": [4, 5, 6]}}}', ["Content-Type"::"application/json"]];
msgSent <- msgSent + 1;
        }

}

experiment debug {
action _init_ {
create simulation;
}
output {
}
}


Java.lang.ClassCastException: class gama.core.util.GamaMap cannot be cast to class java.lang.String (gama.core.util.GamaMap is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @26f5a6cd; java.lang.String is in module java.base of loader 'bootstrap')
        at gama.extension.network.httprequest.HTTPRequestConnector.send(HTTPRequestConnector.java:134)
        at gama.extension.network.skills.NetworkSkill.effectiveSend(NetworkSkill.java:472)
        at gama.core.messaging.MessagingSkill.primSendMessage(MessagingSkill.java:121)

Daniel Howarth

unread,
Apr 23, 2024, 2:51:39 AM4/23/24
to GAMA
I have also tried this with "raw:true" on the connect, and the result is the same.

Benoit Gaudou

unread,
May 5, 2025, 12:19:57 AMMay 5
to gama-p...@googlegroups.com
Just to keep track: I guess you should not use : 

do send to:"/test" contents: ["POST",["a"::1], ["Content-Type"::"application/json"] ];

but

do send to:"/test" contents: ["POST",to_json(["a"::1]), ["Content-Type"::"application/json"] ];


Benoit


--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/cc8dc8db-76c3-4e61-9cf5-9345a330f697n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages