How to get parameter come after '#' in Perl CGI? - perl

How can we fetch the value of folders from below mentioned url:
http://my.indiamart.com/cgi/​my-enquiries.mp#folders=1
I've tried CGI object, %ENV variable and so many things, but still not been able to get it.
Please suggest..

You can't, the browser interprets the fragment (#folders=1) without sending it to the server. So if http://my.indiamart.com/cgi/​my-enquiries.mp is your script, then it will never see the #folders=1 part of the URL as the browser won't send it. If you need the fragment on the server then you'll have to change it to a CGI parameter:
http://my.indiamart.com/cgi/​my-enquiries.mp?folders=1
or embed it in the URL path, something like one of these:
http://my.indiamart.com/cgi/​my-enquiries.mp/1
http://my.indiamart.com/cgi/​my-enquiries.mp/folders=1

You can't, # is recognized by JavaScript only,
apache will ignore this, that's the reason it does not contains any value in ENV variable.
You can use JavaScript: window.location.hash to capture this hash value.

Only with javascript.
You can use something like that to redirect to another script
<script>
if(window.location.hash) {
var str = window.location.hash.substring(1);
window.location.href = 'http://other_script.pl?param=' + str;
}
</script>

Related

How to write Response.redirect with Query_string server variables in ASP

I'm trying to redirect users to my mobile page equivalent of a desktop page. Right now I can only get them to the home page.
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp") End If
I'd like to redirect to the mobile page with the additional correct variables. So the redirect response should be to "/mobile.asp?m=here" from the "/home.asp?m=here" page and "/mobile.asp?m=there" from the "/home.asp?m=there" etc.
I can get the variables with <% Response.Write(Request.ServerVariables("QUERY_STRING")) %> but my syntax must be off when I try to concat the redirect
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp?&Response.Write(Request.ServerVariables("QUERY_STRING"))&""") End If
Little help. Thanks.
You don't need the response.write in there. Something like this (not tested it though)
response.redirect("/mobile.asp?" & Request.ServerVariables("QUERY_STRING"))
In order to put something dynamic into your string it has to be determinated first, then use a & to concatenate other strings / variables. So you want your code to look like this:
If b.test(u) or v.test(Left(u,4)) then response.redirect("/mobile.asp?" & Response.Write(Request.ServerVariables("QUERY_STRING"))) End If
also, you should check for any query strings to know weather to put the ? or not.

Add Page Tab redirect to invalid location

When I've user Add Page Tab Dialog, I've passed redirect_uri like this
http://MYSITE/?r=c/action&token=123456789
when the dialog come back, it strips the token variable, so the url looks like
http://MYSITE/?r=c%2Faction&&tabs_added%5B176281002470701%5D=1#_=_
the token variable lost,
any body have any idea why this happen?
Might be a bug or the forward-slash. Try adding an extra param at the end that you don't care about or removing the forward-slash
http://MYSITE/?r=c/action&token=123456789&t=1
http://MYSITE/?r=caction&token=123456789
One option is to put all your needed variables in a single base64 string and pass that guy over as your single querystring parameter.
Pseudo-code would be:
data = toBase64String("action&token=123456789")
redirect_uri = "http://MYSITE/?data=" + data;
Then you decode it wherever you redirect to.

feedpp and session ID

we are using Perl and cpan Modul FeedPP to parse RSS Feeds.
The Perl script runs trough the different items of the RSS Feeds and save the link to the database, liket his:
my $response = $ua->get($url);
if ($response->is_success) {
my $feed = XML::FeedPP->new( $response->content, -type => 'string' );
foreach my $item ( $feed->get_item() ) {
my $link = $item->link();
[...]
$url contains the URL to an RSS Feed, like http://my.domain/RSS/feeds.xml
in this case, $item->link() will contain links to the RSS article, like http://my.domain/topic/myarticle.html
The Problem is, some webservers (which provides the RSS feeds) does an HTTP refer in order to add an session ID to the URL, like this: http://my.domain/RSS/feeds.xml;jsessionid=4C989B1DB91D706C3E46B6E30427D5CD.
The strange think is, that feedPP seams to add this session-ID to the link of every item. So $item->link() contain links to the RSS article, like http://my.domain/topic/myarticle.html;jsessionid=4C989B1DB91D706C3E46B6E30427D5CD
Even if the original link does not contain an session ID.
Is there a way to turn of that behavior of feedPP??
Thank you for any kind of help.
I took a look through http://metacpan.org/pod/XML::FeedPP but didn't see any way to turn have the link() method trim those session IDs for you. (I'm using XML::FeedPP in one of my scripts and the site I happen to be parsing doesn't use session IDs.)
So I think the answer is no, not currently. You could try contacting the author or filing a bug.
IMHO, the behavior is correct: uri components which follow a semi-colon are defined part of the path (configuration parameter for interpretation), so when the uri is used to make a relative url into an absolute uri it needs to be copied as well.
You expect compatible behavior with '&' parameters, but they are not equal.
https://rt.cpan.org/Ticket/Display.html?id=73895

How to get referrer http header at Gwt Entrypoint

I Couldn't find any class/method which gives me access to the referrer header in GWT.
anyone knows about this?
See
Document.get().getReferrer()
Since you can't get the headers in javascript, I don't think you can get them in a GWT client either: Accessing the web page's HTTP Headers in JavaScript
Update:
Maybe you can update login.php to write out the referrer to a hidden input tag, maybe something like this:
<input type="hidden" name="referrer" name="referrer" value="<?php Print referrer_value ?>">
Then, in gwt you should be able to get the value using something like this:
InputElement elt = (InputElement)Document.get().getElementById("referrer")
String referrer = elt.getValue()
Note: This is untested code, and I'm not even sure that is valid php, but hope this helps!
I had the same question, but I made some changes to charge the header link tag dinamically.
I used this code:
LinkElement link = Document.get().createLinkElement();
link.setHref("css/home.css");
I don't know if is the most graceful solution, but it works!
EDIT:
If you need to modify any current element you should to do this:
NodeList<Element> links = Document.get().getElementsByTagName("link");
for(int i = 0; i < links.getLength(); i++){
LinkElement l = (LinkElement)links.getItem(i);
if( l.toString().contains("href_to_replace.css") ){
l.setHref("new_href.css");
break;
}
}
You can access to the referrer in JavaScript and pass it to Java (rather to the JavaScript compiled from Java). You need to define a JSNI (JavaScript Native Method) method in Java with a JavaScript definition. This code can access the document and window objects of the browser, although you need to respectively use $doc and $wnd variables for that purpose.
More info at
https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI
You can get the full URL String like so:
String url = Document.get().getURL();
get the index of a question mark and parse it by yourself

How can I fill in web forms with Perl?

I want to fill in a web form with Perl. I am having trouble finding out the correct syntax to accomplish this. As in, how do I go to the URL, select the form, fill in the form, and then press enter to be sure it has been submitted?
Something like WWW::Mechanize::FormFiller?
WWW::Mechanize and its friends are the way to go. There are several examples in Spidering Hacks, but you'll also find plenty more by googling for the module name.
Good luck, :)
Start with WWW::Mechanize::Shell:
perl -MWWW::Mechanize::Shell -e shell
get http://some/page
fillout
...
submit
Afterwards, type "script", and save generated code as something.pl - and that's about it. It's done.
Request the form's action URL with Net::HTTP or something (can't recall the exact module), and include the forms fields as a GET/POST parameter (whichever the form calls for).
HTML::Form works nicely, too.
The synopsis of the module is an excellent example:
use HTML::Form;
$form = HTML::Form->parse($html, $base_uri);
$form->value(query => "Perl");
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$response = $ua->request($form->click);