- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to Post JSON data to a site via API functionality: "Unsupported Media Type"
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"<!DOCTYPE html PUBLIC \!"-//W3C//DTD XHTML 1.0 Strict//EN\!" \!"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\!"><html xmlns=\!"http://www.w3.org/1999/xhtml\!"><head><title>GlassFish Server Open Source Edition 4.1 - Error report</title><style type=\!"text/css\!"><!--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;}--></style> </head><body><h1>HTTP Status 415 - Unsupported Media Type</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Unsupported Media Type</p><p><b>description</b>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</p><hr/><h3>GlassFish Server Open Source Edition 4.1 </h3></body></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.