zoukankan      html  css  js  c++  java
  • java后台调用后台接口

    后台调用后台接口并获取返回值:

                  //-----开始------------
    			DefaultHttpClient httpClient = new DefaultHttpClient();
    			String url="http://192.xxx.x.xxx:xxxx/xx/xx";
    			HttpPost httpPost = new HttpPost(url);
    			httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    			List<NameValuePair> nvps = new ArrayList<NameValuePair>();
                  // ----传参---- nvps.add(new BasicNameValuePair("VId",“xxx”)); nvps.add(new BasicNameValuePair("password",“xxx”)); nvps.add(new BasicNameValuePair("telephone", “xxx”)); nvps.add(new BasicNameValuePair("nickName",“xxx”)); try { httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println("0000"); // 执行请求 HttpResponse response = null; try { response = httpClient.execute(httpPost); } catch (IOException e) { System.out.println("0002"); e.printStackTrace(); } System.out.println("0003"); BufferedReader in = null; String content = null; try { System.out.println("0004"); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } content = sb.toString(); } catch (UnsupportedOperationException | IOException e) { e.printStackTrace(); } finally { try { if(in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } }
                  // 打印返回值 System.out.println(content); //------结束--------

      

  • 相关阅读:
    Source Insight 安装使用
    size_t和ssize_t
    jquery ui autoComplete自动完成
    一个php类 Autoloader
    php register_shutdown_function
    mysql concat和group_concat
    nginx反向代理
    6.关于QT中的内存管理,动态的制作,动态库的调用,静态库的制作
    Sublime Text2 按shift键选择不了的问题
    javascript--瀑布流
  • 原文地址:https://www.cnblogs.com/dztHome/p/9019707.html
Copyright © 2011-2022 走看看