简体   繁体   English

如何使用HttpPost传递非String参数?

[英]How can I pass non String parameters with HttpPost?

I use BasicNameValuePair class for passing String parameters with HttpPost in my Android application. 我使用BasicNameValuePair类在我的Android应用程序中使用HttpPost传递String参数。 How can I pass non String parameters like Double, Byte Array etc? 如何传递非String参数,如Double,Byte Array等?

Thanks in advance 提前致谢

Short answer: You can't. 简答:你做不到。 Not really. 并不是的。

Long answer: The stuff that can be easily converted to a string you can just convert to a string (.toString) and parse (Double.parseStr()). 答案很长:可以很容易地转换为字符串的东西,你只需要转换为字符串(.toString)和解析(Double.parseStr())。

Common practice for byte arrays is to encode them in - for instance - Base64. 字节数组的常见做法是将它们编码 - 例如 - Base64。 Android docs here Android文档在这里

将它们转换为字符串?

String.valueOf();

将其解析为字符串

whateverparameter.toString()

You can convert the value to String : 您可以将值转换为String

final Double myDouble = new Double("12.35");
new BasicNameValuePair(MY_DOUBLE_PARAM, myDouble.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM