I have this class in java, I'm using Jersey.
@Path("/bandas")
public class BandaResource {
static private Map<Integer, Banda> bandasMap=someSource();
@GET
@Produces({ "application/json" })
public List<Banda> getBandas()
{
return new ArrayList<Banda>(bandasMap.values());
}
@POST
@Consumes("text/xml")
@Produces("text/plain")
public String adicionaBanda(Banda banda) {
banda.setId(bandasMap.size() + 1);
bandasMap.put(banda.getId(), banda);
return banda.getNome() + " adicionado.";
}
}
In Unity when I request all the information I get an answer from server:
URL url = new URL ( "http://localhost:8080/restful-exemplo/rest/bandas" );
WWW www = new WWW(url);
Debug.Log (www.data) returns:
{"banda":[{"anoDeFormacao":"1968","id":"1","nome":"Led Zeppelin"},{"anoDeFormacao":"1973","id":"2","nome":"AC/DC"}]}
But I want to send, I don't have any idea how but I tried:
string JSON=" {\"nome\":\"Teste\", \"anoDeFormacao\":\"1988\",\"id\":\"4\"}";
Hashtable postHeader = new Hashtable();
postHeader.Add("Content-Type", "text/json");
UTF8Encoding encoding = new System.Text.UTF8Encoding();
WWW request = new WWW(url, encoding.GetBytes(JSON.ToCharArray()), HashtableToDictionary<string, string>(postHeader));
Well, it returns a error (WWW Error: 415 Unsupported Media Type ), is the idea correct?