2011-12-21 84 views
0

我需要使用一些服務。 ,我需要調用的服務方法需要得到兩個參數 1. INT 2.一些枚舉如何在需要調用http post調用時發送參數?

我不知道如何發送這些參數和如何使這個電話。 我想使用此代碼

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作爲參數(僅字符串) 第二個參數(這是一些枚舉),我認爲我可以爲字符串發送和服務另一方會將此字符串轉換爲枚舉(對不對?)

回答

1

使用String.valueOf用於intEnumtoString方法(它返回Enum作爲String的名稱)。

服務器如何處理這些數據取決於它是如何編碼的。

1

您總是發送變量作爲String服務器上的代碼將按照它的意願解釋數據。

1

發送數據,你已經在做。服務器端:解析和驗證數據,例如

If(int.tryparse(datareceived)) 
{ 
    Response.write("success"); 
} 
else 
    Response.write("bad data"); 
+0

夥計們...服務器端不在我的控制之下:) – Yanshof 2011-12-21 12:46:27