我已经有了下面这段代码:
我从各种示例中摆弄代码得到了这个,不确定客户端应该是什么对象,第一行是否只会让我获得服务器响应,或者我必须获取InputStream并读取服务器响应?请帮助我正确理解如何做。谢谢!
private class DownloadWebPageTask extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... theParams)
{
String myUrl = theParams[0];
String myEmail = theParams[1];
String myPassword = theParams[2];
HttpPost post = new HttpPost(myUrl);
post.addHeader("Authorization","Basic "+ Base64.encodeToString((myEmail+":"+myPassword).getBytes(), 0 ));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = null;
try
{
response = client.execute(post, responseHandler);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null)
{
response += s;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result)
{
}
}
这段代码无法编译,因为我在以下代码处遇到了困惑:
response = client.execute(post, responseHandler);
InputStream content = execute.getEntity().getContent();
我从各种示例中摆弄代码得到了这个,不确定客户端应该是什么对象,第一行是否只会让我获得服务器响应,或者我必须获取InputStream并读取服务器响应?请帮助我正确理解如何做。谢谢!