
我需要使用httpPost将包含%(EX:abc%xyz)的字符串发送到webservice.
我使用了以下逻辑,但我在(%)处获得了IllegalCharacter异常.
**updatepeople.PHP?pilotID=1651&firstname=Nexus&lastname=Google&nickname=abc%xyz** final int TIMEOUT_MILliSEC = 20000; httpParams httpParams = new BasichttpParams(); httpconnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILliSEC); httpconnectionParams.setSoTimeout(httpParams, TIMEOUT_MILliSEC); httpconnectionParams.setTcpNoDelay(httpParams, true); httpClIEnt httpClIEnt = new DefaulthttpClIEnt(httpParams); URLEncoder.encode(url, "UTF-8"); httpPost httpPost = new httpPost(url); ResponseHandler<String> resHandler = new BasicResponseHandler(); page = httpClIEnt.execute(httpPost, resHandler); return page;解决方法:
在查询字符串中传递值时尝试使用此代码,而不是将此传递为实体.
现在你的网址只包含页面链接没有任何参数,它将以updatepeople.PHP结束
httpPost httpPost = new httpPost(url);List<nameValuePair> param = new ArrayList<nameValuePair>();param.add(new BasicnameValuePair("pilotID", "1651"));param.add(new BasicnameValuePair("firstname", "Nexus"));param.add(new BasicnameValuePair("lastname", "Google"));param.add(new BasicnameValuePair("nickname", "abc%xyz"));httpPost.setEntity(new Unew UrlEncodedFormEntity(param));现在执行它并继续尽可能地继续
总结以上是内存溢出为你收集整理的如何在android中使用HttpPost将包含%符号的字符串发送到webservice?全部内容,希望文章能够帮你解决如何在android中使用HttpPost将包含%符号的字符串发送到webservice?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)