gpt4 book ai didi

android - 如何在 Post 方法上获取内容

转载 作者:行者123 更新时间:2023-11-29 22:00:34 27 4
gpt4 key购买 nike

我已经为 HttpPost 使用了下面的代码,它执行成功了。但无法看到响应。我得到了 InputStream。我想知道里面的内容是什么。

我想显示为字符串格式。如何做到这一点。

        HttpPost httppost = new HttpPost(requestURL);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.length);

for (int postValueCount = 0; postValueCount < params.length; postValueCount++)
nameValuePairs.add(new BasicNameValuePair(params[postValueCount][0],params[postValueCount][1]));

try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d("HttpPostRequest","URL : " + httppost.getRequestLine().getUri());
Log.d("HttpPostRequest","Method : " + httppost.getRequestLine().getMethod());
Log.d("HttpPostRequest","Parameters : " + nameValuePairs);
response = httpclient.execute(httppost);
status = response.getStatusLine();

if (status.getReasonPhrase().equals("OK")) {
httpEntity=response.getEntity();
InputStream in = httpEntity.getContent();
return in;
} else {
Log.d("Http Status", status.getReasonPhrase());
}

}

最佳答案

使用这段代码:

HttpEntity entity = response.getEntity();
String response = EntityUtils.toString(entity);

关于android - 如何在 Post 方法上获取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12033012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com