无法输出到控制台"POST“请求正文
HttpClient client= HttpClientBuilder.create().build();
HttpPost request=new HttpPost("https://reqres.in/api/register");
List<NameValuePair> params= new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email","eve.holt@reqres.in"));
params.add(new BasicNameValuePair("password","pistol"));
request.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(request);我想要查看请求的正文(电子邮件、密码)。
我尝试过System.out.println(request.getEntity()),但它并不完全相同
发布于 2019-05-30 00:14:08
Apache httpclient以HttpPost的形式创建一个模型,这不是一个原始请求。当您使用execute()时,将在内部将其转换为HTTP有效负载并进行处理,然后再次以建模对象的形式向您呈现响应。
您可以使用Wire logger:org.apache.http.wire来记录请求和响应。更多信息请点击这里:https://hc.apache.org/httpcomponents-client-4.5.x/logging.html。
原始数据似乎在org.apache.commons.httpclient.HttpConnection中可用,但您必须覆盖相当多的httpclient组件才能将其提取出来。
https://stackoverflow.com/questions/56363600
复制相似问题