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

      

  • 相关阅读:
    Eclipse 插件Maven在使用 add dependency,找不到包,解决办法
    SimpleDateFormat是线程不安全的,切忌切忌!
    JNative 传递参数bug
    oracle存储过程递归调用
    oracle调用DLL
    telnet和Netstat使用
    notepad++搭配dev配置运行C++
    ubuntu第一次安装登陆密码不正确问题
    区分形参和实参
    爬虫2
  • 原文地址:https://www.cnblogs.com/dztHome/p/9019707.html
Copyright © 2020-2023  润新知