我試過這個例子,它可以很好的與示例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
嘗試發佈您的代碼爲我們調試 –