使用 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();
像这样休息方法:
@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;
}
我究竟做错了什么?