HTTP POST with JSON

Hi, trying to do a REST call with

	var vJSON = plugins.serialize.fromJSON("{'ID':'XXX23456','Details':[{'ACMyFee':332.65,'ACmyRate':45.0,'ACUUID':'FDB895C9-5B03-4AEE-BEAA-E5A235A00555','ACNumber':2345}]}")
	var vURL = "http://localhost:8080/servoy-service/rest_ws/mod_rest_ws/ws_api"
	plugins.http.setTimeout(10)
	var poster = plugins.http.getPoster(vURL)  
//	var didAddParam = poster.addParameter('claim',vJSON);
//	var didAddFile = poster.addFile('myFileParamName','manual.doc','c:/temp/manual_01a.doc');
	poster.addParameter("Content-Type","application/json")
	poster.setCharset('UTF-8')
	poster.addParameter(null,vJSON)
	var httpCode = poster.doPost(); //httpCode 200 is ok
	var pageData = poster.getPageData()

I keep getting Error 415 - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method

I’ve tried variations on the format of the JSON, the parameters etc with no luck

Hi Tony,

I’m not so familiar with the serialize plugin, I always use the one from the velocity plugin (servoyforge.net)
Anyway, looking at the tooltips of this plugin, I think you need to go the other way around, ‘plugins.serialize.toJSON’.

One tip: just try to see what the vJSON variable contains.
If you are not able to read it, the webservice certainly won’t be able to…

Tony,

The poster.addParameter(null,vJSON) call should get a string, not the parsed object.

Rob

Thanks for the assistance, this worked.

 var vJSON = plugins.serialize.toJSON("{'ID':'XXX23456','Details':[{'ACMyFee':332.65,'ACmyRate':45.0,'ACUUID':'FDB895C9-5B03-4AEE-BEAA-E5A235A00555','ACNumber':2345}]}")
   var vURL = "http://localhost:8080/servoy-service/rest_ws/mod_rest_ws/ws_api"
   plugins.http.setTimeout(10)
   var poster = plugins.http.getPoster(vURL)  
   poster.addHeader('Content-type','text/json; charset=UTF-8')
 //  poster.addParameter("Content-Type","application/json")
 //   poster.setCharset('UTF-8')
   poster.addParameter(null,vJSON)
   var httpCode = poster.doPost(); //httpCode 200 is ok
   var pageData = poster.getPageData()

In fact it also works with vJSON = “{‘ID’:‘XXX23456’,‘Details’:[{‘ACMyFee’:332.65,‘ACmyRate’:45.0,‘ACUUID’:‘FDB895C9-5B03-4AEE-BEAA-E5A235A00555’,‘ACNumber’:2345}]}”