// hack to support POST by encoding into URL
// http://xxxx/index.php?main=search&azmethod=post_basic:SearchString1=%s&SearchString=&search=Search
ResourceDownloaderFactory rdf = StaticUtilities.getResourceDownloaderFactory();
URL initial_url;
ResourceDownloader initial_url_rd;
int post_pos = searchURL.indexOf( "azmethod=" );
if ( post_pos > 0 ){
String post_params = searchURL.substring( post_pos+9 );
searchURL = searchURL.substring( 0, post_pos-1 );
debugLog( "search_url: " + searchURL + ", post=" + post_params );
initial_url = new URL(searchURL);
int sep = post_params.indexOf( ':' );
String type = post_params.substring( 0, sep );
if ( !type.equals( "post_basic" )){
throw( new SearchException( "Only basic type supported" ));
}
post_params = post_params.substring( sep+1 );
// already URL encoded
initial_url_rd = rdf.create( initial_url, post_params );
initial_url_rd.setProperty( "URL_Content-Type", "application/x-www-form-urlencoded" );
}else{
debugLog( "search_url: " + searchURL );
initial_url = new URL(searchURL);
initial_url_rd = rdf.create( initial_url );
}
setHeaders( initial_url_rd, headers );
if ( needsAuth && local_cookies != null ){
initial_url_rd.setProperty( "URL_Cookie", local_cookies );
}
if ( only_if_modified ){
String last_modified = getLocalString( LD_LAST_MODIFIED );
String etag = getLocalString( LD_ETAG );
if ( last_modified != null ){
initial_url_rd.setProperty( "URL_If-Modified-Since", last_modified );
}
if ( etag != null ){
initial_url_rd.setProperty( "URL_If-None-Match", etag );
}
}
InputStream is;
String content_charset = "UTF-8";
ResourceDownloader mr_rd = null;
if ( initial_url.getProtocol().equalsIgnoreCase( "file" )){
// handle file://c:/ - map to file:/c:/
String str = initial_url.toExternalForm();
if ( initial_url.getAuthority() != null ){
str = str.replaceFirst( "://", ":/" );
}
int pos = str.indexOf( '?' );
if ( pos != -1 ){
str = str.substring( 0, pos );
}
is = new FileInputStream( new File( new URL( str ).toURI()));
}else{
mr_rd = rdf.getMetaRefreshDownloader( initial_url_rd );
try{
is = mr_rd.download();