Hi There,
I am trying to perform a POST request to post some JSON data to a server, but unfortunately as of now I keep getting a 415 error. The goal of this script is to upload a JSON formatted file (or something of the like) to the server for other users to download/read. I noticed that there are very few POST examples with JSL, but quite the abundance with GET, which I have no problems with. I was wondering if anyone else has encountered this sort of error/knows the solution to such a problem. Unfortunately, while I can't show some of the details (namely the server name and API Key), I can provide some of the script that I used to generate the request:
//Create an Associative Array/Dictionary that can be converted to JSON format
aa=Associative Array();
aa<<Insert("Var1",1);
aa<<Insert("Var2",2);
aa<<Insert("Var3",3);
//Send the POST request, using JSON(aa). This yields a 415 error
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
URL( url ), // the restAPI endpoint
Method( "POST" ),
JSON(aa);
);
data=request<<Send();
Write(data);
//Version that first converts the associative array/dictionary to a JSON, then performs the POST request. This too, yields a 415 error
json=As JSON Expr(aa);
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
URL( url ), // the restAPI endpoint
Method( "POST" ),
JSON(json);
);
data=request<<Send();
Write(data);
So far, my attempts have consistently resulted in the following in the log:
HTTP/1.1 415 Unsupported Media Type<BR />"<!DOCTYPE html PUBLIC \!"-//W3C//DTD XHTML 1.0 Strict//EN\!" \!"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\!"><BR /><html xmlns=\!"http://www.w3.org/1999/xhtml\!"><BR /><head><BR /><title><BR />GlassFish Server Open Source Edition 4.1 - Error report<BR /></title><BR /><style type=\!"text/css\!"><BR /><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--><BR /></style><BR /> </head><BR /><body><BR /><h1>HTTP Status 415 - Unsupported Media Type</h1><BR /><hr/><BR /><p><BR /><b>type</b><BR /> Status report</p><BR /><p><BR /><b><BR />message<BR /></b><BR />Unsupported Media Type<BR /></p><BR /><p><BR /><b><BR />description<BR /></b><BR />The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.<BR /></p><BR /><hr/><BR /><h3><BR />GlassFish Server Open Source Edition 4.1 <BR /></h3><BR /></body><BR /></html>"Once again, if anyone else has experienced this, or knows the solution to such a problem, any help would be much appreciated!
EDIT: I should probably clarify that I am trying to Post onto Dataverse, if that is of any help.