java http post from表单提交

大兔子大兔子 提交于 2020-02-26 12:03:14
  public static String httpExecute( List<BasicNameValuePair> pairList, String url)
    {
        try {
            HttpPost httpPost = new HttpPost(url);
            CloseableHttpClient client = HttpClients.createDefault();
            String respContent = null;
           httpPost.setEntity(new UrlEncodedFormEntity(pairList,"utf-8"));

            HttpResponse resp = client.execute(httpPost);
            if (resp.getStatusLine().getStatusCode()==200)
            {
                HttpEntity he = resp.getEntity();
                respContent = EntityUtils.toString(he,"utf-8");
            }
            return respContent;
        }catch (Exception e) {
            log.error("http post error: " + e);
        }
        return null;
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!