我是一名新手,正在开发 Android 应用程序。我的应用程序运行良好,直到主机没有将他的网页设置为重定向到其他页面。现在我得到一个 html 页面代码
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>Moved</TITLE>
</HEAD>
<BODY>
<H1>Object Moved</H1> this document may be found <a href="some url">here</a>
</BODY>
</HTML>
试过 conn.setInstanceFollowRedirects(false); 但仍然没有用。如果我使用 GET 方法,我会得到这个,但是在使用 POST 方法时,我会得到很多空格。请帮忙。
enter code here
这是我在 doinbackground() 中的代码
protected Void doInBackground(String... param) {
try
{
HttpClient httpclient = new DefaultHttpClient(){
@Override
protected RedirectHandler createRedirectHandler() {
return new DefaultRedirectHandler(){
@Override
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
rep="httpclient redirect";
return false;
}
};
}
};
HttpGet httppost = new HttpGet(param[0]);
httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);
httppost.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
rep+=responseBody;
}
catch (Exception e)
{
if(e.getMessage()==null)
rep+="No response from server";
else
rep+="Error: " + e.getMessage();
}
}`enter code here`