Server.callWithPost content type
-
Hi there, I'm not experienced in API calls nor server handling.
Im trying a few external APIs and I see many requieres Content-Type: application/json encoded requests instead of the x-www-form-urlencoded HISE uses on Server.callWithPost
this is how a Content-Type: application/json looks:
'{\n "text": "hello",\n "time": 5\n}'
And this is how a x-www-form-urlencoded from HISE looks:
'text=hello&time=5'
How can I change this ?
Thanks mates! -
Any clue anyone??
-
@hisefilo said in Server.callWithPost content type:
x-www-form-urlencoded
Why do you think HISE uses this?
You can (should) send a JSON object with your POST requests.
Here's an example - https://codeberg.org/LibreWave/Rhapsody/src/branch/main/Scripts/LicenseHandler.js#L99
-
@d-healey I tested with a local python server (attached) and got this for headers. Despite this, I think HISE is sending form-urlencoded format, and the APIs I'm testing expect a JSON dictionary for the body.
Interface: "Host: 127.0.0.1:4000\nContent-Type: application/x-www-form-urlencoded\nUser-Agent: HISE%20Standalone/4.1.0 CFNetwork/1410.0.3 Darwin/22.6.0\nConnection: keep-alive\nAccept: */*\nAccept-Language: en-GB,en-US;q=0.9,en;q=0.8\nContent-Length: 41\nAccept-Encoding: gzip, deflate\nnxi-api-key: sk_f3298fc4aeccb17ab56044222219110d7e044e921ac1cc1a\n\n\r\ntext=hi%20there&duration_seconds=5"
7f43a9fdd0a9d638d8634cca4b5ac824-12602f5c1fdc8a35112ca130a4de9cb890109cc3.zip
-
@hisefilo I've just tested and it is indeed sent as application/x-www-form-urlencoded by default.
You can specify the content-type you'd like to use by setting a http header before making the POST request.
Server.setHttpHeader("Content-Type: application/json");
I'm using this site to test - https://posttestserver.dev/
-
@d-healey Yes, header does not seems to be the problem for me. I know hot to add it.
The JSON itself is sent as form-urlencoded and I guess I need it JSON object
like this:'{\n "text": "hello",\n "time": 5\n}'
This is an api call to openai I was playing with. But no luck. credentials are active.
HiseSnippet 1212.3ocsVs0aaaCElJIpq1ccXEXOtGH7StCI1VwNNWFFVicRZbRiiWbtzhsg.ZI5JFSQpRR4Zuh9ed+C1NTVwWZS1JB1zCB5bke5bkcTRepVKUHm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nFPJrHvw8K3XGM+FgwySXni.e7X28ECYDk8G6Sc7Syb7qH8n7T+9DWyHKLifwU2mma8hId9QtgRN4KyuO0k2ieVVw28542j44u2cea4IlJvbBFJeY9LSRvN3ZUpAq39rowvd.YPBmXVb4fcEZl.nJagIx1otBMyLd9D1+YaL9Rg3yb6vL9g2MFW5NvHTK8+AFy1y9T2862m5alAvUbO30++rTEcFLzjId6IDihA0CtsSh5B2MwmBmtPP41tbmkr8iSnqXosQ.aUeJweAOYB8rzNYB8tUHJh3qjW6OoK1tI+wob.LIRu0SN2SrzXuOs4EghfKVbsu+ht5yLb8GpgUenFV6gZ3FOTCq+PMbyGpga8uan8dev0WjQSZaPnS5re5vVGm8EDnBLsZE82v9LJiT
-
@hisefilo You need to set these are separate headers I think.
Server.setHttpHeader("Content-Type: application/json\nAuthorization: Bearer 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");
I'm seeing this in the console with your snippet
Interface: {
"error": {
"message": "Invalid URL (POST /v1/chat/completions/)",
"type": "invalid_request_error",
"param": null,
"code": null
}
} -
@d-healey here's clear. posted on posttestserver.dev via HISE, and via mac terminal cURL
HISE json (see body)
cURL Json
-
@hisefilo said in Server.callWithPost content type:
here's clear. posted on posttestserver.dev via HISE
Share snippet
-
HiseSnippet 1213.3ocsVs0TabCEVKvlI3zzoYl9XePiexoCDaiWLW5zoAaffgfwEykjosCi7txrBKKsHo0wtYx+49On8ncWrWHPaFll8AOVma5Smy24H0QI8oZsTgbJbxjHJx4ab6NQXBaFRXBTqsQNemaGo1bBUa5RUinJTiIQDslFfbbl+MVqbVbATx2e8KMHbhvmNSDBclj4SeKaHyLSZmWe.iy2kDPOgMLm0dutkuTzTxkw.hl2sBJh3OfbIsMwZ1btn8H5PjyO5VY05T5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b41mMGFtAPFDyIlaesf8xyLE.K6VyhsyaEZlYR9B1+a2U7kBwW31gY7CueLN28fQfK80.iY2v9b2c52m5alAvEb28cectNEcLLnjIt7PhQw.9fa63gcgWk3SgcWHnbaWtyb19wz0UrqsY.KqOYweCeYJqZW6jor5MJQCI9J4E9ocw16veZhD.Shj26rn6g103p2s4EgFBOo3Be+aGpOywUdrNV6w5n2i0wUerNV+w53ZOVGW++1Q6K9fWsHGl11fPG1YmjgsNN6HH.CLgsh9G.3GcMqA
-
@hisefilo Yeah looks like HISE (or JUCE) is repackaging the data. One for Christoph I think.
-
@d-healey thanks mate for taking the time! hope @Christoph-Hart can take a look!