今天跑ap遇到這個問題

java.net.MalformedURLException: no protocol: %E6%9C%8D%E9%A3%BE

發現原來是因為傳給url的值必須是帶有http://開頭的url位址

最重要是把傳入值keyword改成search即可



int page=1;

String search="";

String keyword="服飾";

keyword = code.Utf8URLencode(keyword);



search="http://tw.search.yahoo.com/search?p="+keyword+"&ei=UTF-8&b="+page;



//yahoo.connect(keyword);

yahoo.connect(search);



public void connect( String urlString ) {

try {

URL url = new URL(urlString);

connection = url.openConnection();

connection.setConnectTimeout(10000);

connection.setReadTimeout(10000);



} catch (MalformedURLException e){

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (Exception e){

e.printStackTrace();

}

}


狼翔月影 發表在 痞客邦 PIXNET 留言(0) 人氣()