我需要使用一些服务。 我需要调用的服务方法需要获取两个参数 int 2.一些枚举
我不知道如何发送这些参数以及如何进行此调用。 我想使用这段代码
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("param1", val1);
nameValuePairs.add(new BasicNameValuePair("param2", val2);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse p = httpclient.execute(httppost);
但是这段代码不能作为参数发送int(只有字符串) 第二个参数(即一些枚举)我认为我可以作为字符串发送,而另一方的服务会将此字符串转换为枚举(我是对的吗?)
答案 0 :(得分:1)
您总是将变量发送为String
服务器上的代码按照自己的意愿解释数据。
答案 1 :(得分:1)
使用String.valueOf
代表int
和toString
Enum
方法(将Enum
的名称作为String
返回)。
服务器如何处理这些数据取决于它的编码方式。
答案 2 :(得分:1)
按照您现有的方式发送数据。服务器端:解析并验证数据,例如
If(int.tryparse(datareceived))
{
Response.write("success");
}
else
Response.write("bad data");