当前位置: 代码迷 >> Android >> 关于APP的调用webService的有关问题
  详细解决方案

关于APP的调用webService的有关问题

热度:61   发布时间:2016-04-28 06:05:11.0
关于APP的调用webService的问题
本帖最后由 hutao93 于 2014-04-03 20:58:54 编辑
近来公司要做Android应用,但是数据是调用的webService。
不知道各位有没有关于怎么写Android的webService的文章和帖子。

写的太简单是不是很lower?
------解决方案--------------------
没什么的,就用httpclient请求服务器的Webservice
------解决方案--------------------
参考


/**
 * a http request with given url
 * @param strUrl the url you want to request
 * @return
 */
public static String request(String strUrl){

logger.debug(CommonHTTPRequest.class.getName() + ", request url is : " + strUrl);

String userHome = System.getProperty("user.home");
if(userHome.contains("eacfgjl")){
useProxy = true;
}

if(useProxy){
initProxy();
}
        URL url = null;
        String result = "";
        HttpURLConnection urlConn = null;
        InputStreamReader in = null;
        try {
url = new URL(strUrl);
urlConn = (HttpURLConnection) url.openConnection();
in = new InputStreamReader(urlConn.getInputStream());
BufferedReader br = new BufferedReader(in);

String readerLine = null;
while((readerLine=br.readLine())!=null){
result += readerLine;
}
in.close();
urlConn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(ExceptionUtil.getTrace(e));
} catch (IOException e) {
e.printStackTrace();
logger.error(ExceptionUtil.getTrace(e));
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(ExceptionUtil.getTrace(e));
}
urlConn.disconnect();
}
        
        return result;
}

------解决方案--------------------
http://blog.csdn.net/baiyuliang2013/article/details/21979037
  相关解决方案