使用Luke的RestClient for Android并将其称为:
String baseurlString = "http://10.0.2.2:8080/WebTest/jaxrs/ws/testlist";
RestClient client = new RestClient(baseurlString);
String list = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><pairs><pair><_id>1</_id><_version>12</_version></pair></pairs>";
client.AddParam("list", list);
client.AddHeader(ContentType, MediaType.UrlEncoded);
try
{
client.Execute(RequestMethod.POST);
}
catch (Exception e)
{
e.printStackTrace();
}
String responseString = client.getResponse();
To Rest方法如下:
@POST
@Path("testlist")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public List<Pair> insertList(@FormParam("list") List<Pair> pairs)
{
return pairs;
}
由于没有List按预期工作:
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public Pair insertValue(@FormParam("pair") Pair pair)
{
return pair;
}
我做错了什么?