我试过这个例子,它可以很好的与示例URL(http://search.yahoo.com/search
),但当我这样做“http://www.ilias.de/docu/ login.php?target = & client_id = docu“,我无法正确地在webview中看到响应。我的意思是,所有文字都是可见的,但图像不是。并且链接不起作用。HTTP POST对webview的响应无法正常工作
我该如何解决这个问题?
public class ilias extends Activity {
WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.webview);
BufferedReader bufferedReader = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost("http://www.ilias.de/docu/login.php?client_id=docu");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", "stacked")); //This username
postParameters.add(new BasicNameValuePair("password", "overflow")); //works.
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters);
request.setEntity(entity);
HttpResponse response= httpClient.execute(request);
bufferedReader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + LineSeparator);
}
bufferedReader.close();
Toast.makeText(ilias.this,
"Finished",
Toast.LENGTH_LONG).show();
String webData = stringBuffer.toString();
webData = webData.replace("#", "%23");
webData = webData.replace("%", "%25");
webData = webData.replace("\\", "%27");
webData = webData.replace("?", "%3f");
webView.loadData(webData,
"text/html",
"UTF-8");
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ilias.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ilias.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
finally{
if (bufferedReader != null){
try {
bufferedReader.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
这是我有:http://img64.imageshack.us/img64/4913/deviceyl.png,这就是我想要的:http://img200.imageshack.us/img200/8591/device1g.png
尝试发布您的代码为我们调试 –