NSURL load不到search query

  • warning: Declaration of views_handler_argument::init(&$view, &$options) should be compatible with views_handler::init(&$view, $options) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_argument.inc on line 745.
  • warning: Declaration of views_handler_filter::options_validate(&$form, &$form_state) should be compatible with views_handler::options_validate($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • warning: Declaration of views_handler_filter::options_submit(&$form, &$form_state) should be compatible with views_handler::options_submit($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • warning: Declaration of views_handler_filter_boolean_operator::value_validate(&$form, &$form_state) should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 149.
  • warning: Declaration of views_plugin_style_default::options(&$options) should be compatible with views_object::options() in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_style_default.inc on line 25.
  • warning: Declaration of views_plugin_row::options_validate($form, &$form_state) should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • warning: Declaration of views_plugin_row::options_submit($form, &$form_state) should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.

NSURL load不到search query:2011年04月04日星期一

設定search engine string,例如:http://www.google.com/search?q=query(query內為八卦), 用q=query語法後,[myWebView loadrequest:request];竟load不到search結果。

原因:query並非URL coding。URL coding有其定義。基本上為英文字母數字。如上例query內為八卦就不行了。因此需將八卦二字轉為URL coding,也就是成為%2A%2B之類的東西。

解法:

NSString *query = [[aText stringByReplacingOccurencesOfString:@" " withString:@"+" ] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

以上 stringByAddingPercentEscapesUsingEncoding就是將UTF8String換成URL coding關鍵。前面stringByReplacingOccurencesOfString只是將空白換成+號,否則空白也會變成URL coding。