gpt4 book ai didi

java - 在android中使用HTTPClient处理Post请求时获取 "Couldn' t从STDIN读取CGI输入

转载 作者:行者123 更新时间:2023-11-30 03:56:30 28 4
gpt4 key购买 nike

我目前正在开发一个android应用程序,提交一个post请求并处理相应的响应。

我能够将发布请求发送到相应的 URL,但是当我尝试检索响应时,我得到了一半的 HTML 内容,然后是“*无法从 STDIN 读取 CGI 输入。在 ALLOC_READ 0* 之后“

谁能帮我解决这个问题。

下面是代码 fragment

private void processRequest(String... params){

HttpPost post = new HttpPost("http://www.xyz.com");
HttpParams httpParams = post.getParams();
pnr = params[i];
httpParams.setParameter("param1", params[i]);
//User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1");

post.setParams(httpParams);
HttpClient client = new DefaultHttpClient();

try {
HttpResponse response = client.execute(post);

HttpEntity entity = response.getEntity();


try {
processHtmlString(pnr, inputStreamToString(entity.getContent()).toString());
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
client.getConnectionManager().shutdown();
}
}


private String processHtmlString(String pnr, String htmlString) throws Exception{

int index = 0;
while(index < htmlString.length()){
int endIndex = (index + 3000) < (htmlString.length()) ? (index + 3000) : htmlString.length();
Log.i("HttpHelper1","HTML1 : "+htmlString.substring(index, endIndex));
index += 3000;
}
}

输出是 ..........无法从 STDIN.AFTER ALLOC_READ 0 读取 CGI 输入

最佳答案

看起来您没有正确形成请求(您将参数放入相同的节标题中,而不是正文中):试试这个。

    List<NameValuePair> bodyParams = new ArrayList<NameValuePair>();
bodyParams.add(new BasicNameValuePair("param1", params[i]);
if (bodyParams.size() > 0) {
try {
// Include the request body
post.setEntity(new UrlEncodedFormEntity(bodyParams));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Body parameters produced unsupported encoding?", e);
}
}

关于java - 在android中使用HTTPClient处理Post请求时获取 "Couldn' t从STDIN读取CGI输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13258171/

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