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); //------结束--------

      

  • 相关阅读:
    使div浮动层显示在Select组件上面
    JS中,执行字符串的函数
    如何让Web自定义控件(WebCustomControl)能够被 验证控件 验证
    WIN 2003 中 IIS MIME 问题,导致FLV无法播放
    Response.ContentType的所有類型
    XPath语法
    如何加快页面加载速度
    网页页面实现自动刷新的3种代码
    div 内table 居中
    C#中调用Windows API的要点
  • 原文地址:https://www.cnblogs.com/dztHome/p/9019707.html
Copyright © 2011-2022 走看看