in reply to Re: I don't think it's crypt::ssleay either.
in thread problem with german chars in html post fetch
However, I am still not able to post my request successfully using "DWIM" perl, and am forced to use the function I rolled myself. I revised my script (below) to output the same two html files as before, plus an attempt encoding with cgi::enurl, another attempt with Escape::uri_escape, and an attempt with a regex suggested in Perlfaq9 ("") none of which worked, unfortunately.
According to the documentation, cgi::enurl should do what's needed here, but as the above script demonstrates, it fails where my hand rolled function succeeds.
Any ideas?
Update: added test for posting with uri_escape (unfortunately doesn't work either) Update 2: added test for posting with uri encoding regex suggested in perlfaq9 (still doesn't work) Update 3: added function that dumps supperted on my system, into a text file. Currently this outputsuse strict; use HTTP::Request::Common; # HTTP handling use LWP::UserAgent; # HTTP handling use crypt::ssleay; use CGI::Enurl; use URI::Escape; use Encode; use Data::Dumper; my $query = 'börse'; my $www; # Returns a list of the canonical names of the available encodings tha +t are loaded. # http://cpan.uwinnipeg.ca/htdocs/Encode/Encode.html # on my system, this outputs: #$VAR1 = [ # 'ascii', # 'ascii-ctrl', # 'iso-8859-1', # 'null', # 'utf8' # ]; my @list = Encode->encodings(); open F, "> encodingsOutput.txt" or die "Cannot open encodings output." +; print F Dumper(\@list); close F; #doesn't work. #sends $query = 'börse'; $www = google_keyword_suggestions_html_debug('de', 'de', $query); open F, "> suggestionsOriginal.html" or die "Cannot open."; print F '$query: ' . "$query\n"; print F $www->content,"\n"; close F; #doesn't work either. #sends queryDoesntWorkEnurl: b%F6rse my $query_enurl = enurl($query); $www = google_keyword_suggestions_html_debug('de', 'de', $query_enurl) +; open F, "> suggestionsEnurl.html" or die "Cannot open."; print F '$query_enurl:' . "$query_enurl:\n"; print F $www->content,"\n"; close F; #encoding with uri_escape doesn't work either #sends b%F6rse (same as en_url) my $query_uri_escape = uri_escape($query); $www = google_keyword_suggestions_html_debug('de', 'de', $query_uri_es +cape); open F, "> suggestionsUriEscape.html" or die "Cannot open."; print F '$query_uri_escape: ' . "$query_uri_escape\n"; print F $www->content,"\n"; close F; #encodes with regex suggested in perlfaq9 #sends ?b%f6rse (same as en_url, except lower case.) my $query_regexPerlfaq9 = query_regexPerlfaq9($query); $www = google_keyword_suggestions_html_debug('de', 'de', $query_regexP +erlfaq9); open F, "> suggestionsPerlfaq9Regex.html" or die "Cannot open."; print F '$query_regexPerlfaq9: ' . "$query_regexPerlfaq9\n"; print F $www->content,"\n"; close F; s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg; # encode #works -- keyword suggestions are retrieved #sends $query = 'börse'; #keyword suggestions are retrieved, although the html is kind of warpe +d looking. my $query_works = germanchars_to_strange_html_chars($query); $www = google_keyword_suggestions_html_debug('de', 'de', $query_works) +; open F, "> suggestionsRolledMyOwn.html" or die "Cannot open."; print F '$query_works: ' . "$query_works\n"; print F $www->content,"\n"; close F; # returns $www object containing html for a successful code, or an err +or code sub google_keyword_suggestions_html_debug { my $language = shift; my $country = shift; my $query = shift; #this could be a list, but leaving it as a sing +le word. maybe change later. my $action = POST 'https://adwords.google.com/select/KeywordSandbox', [ 'save' => "save", 'wizard_name' => "keywordsandbox_wizard", 'language' => $language, 'country' => $country, 'keywords' => $query, ]; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); $ua->timeout(30); my $www = $ua->request( $action ); return $www; } # Takes a variable and spits it back out with the proper german charac +ters sub germanchars_to_strange_html_chars { my $var = shift; my %table = ( 'ß' => 'ß', 'ä' => 'ä', 'ö' => 'ö', 'Ä' => 'ä', 'Ö' => 'ö', 'Ü' => 'ü', 'ü' => 'ü'); while (my ($k,$v) = each %table) { $var =~ s/$k/$v/g; } return $var; } #based on suggestion in perl faq9 sub query_regexPerlfaq9 { my $var = shift; $var =~ s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg; # encode return $var }
$VAR1 = [ 'ascii', 'ascii-ctrl', 'iso-8859-1', 'null', 'utf8' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending post via enurl doesn't work either (though from documentation seems like it should)
by holli (Abbot) on Jan 10, 2005 at 10:50 UTC | |
by tphyahoo (Vicar) on Jan 11, 2005 at 16:30 UTC | |
by tphyahoo (Vicar) on Jan 12, 2005 at 15:58 UTC | |
by tphyahoo (Vicar) on Jan 10, 2005 at 11:37 UTC |