Submit webform via URL only? - url

I'm not really sure this belongs here, so instead of downvoting just lemme know if so and I'll quickly move it on.
Anyway, there is a website that has a search page, that when hitting the search button it doesn't include the search query in the URL.
After searching for something, the page is redirected to ssearch.asp, but as said, the query isn't there.
My question is if there is a way to submit the search values solely via URL.
I was wondering if there is a way to fake the search-submit button and post the search term
via URL according to form field names.
The name of the input box is search, so I tried this URL: http://www.torec.net/ssearch.asp?search=query, but it doesn't work, the server returns:
server error.
Just to be clear, I'm not looking for a server-side solution, and actually nor for a HTML solution, I just want to be able to paste a plain old URL in my browsers address bar and be there.
Is this possible?
Update
This link doesn't work:
http://www.torec.net/ssearch.asp?search=dark&page=1
While this one does:
http://www.torec.net/ssearch.asp?search=dark&page=2
Any way to bypass this?

Sometimes servers conflate GET and POST parameters, as in PHP $_REQUEST hash. However, normally they are separate - and a server that expects its parameters in multipart/form-data might not look at URL at all. In such a case, as it seems to be here, you have to construct a POST request. On the client side you can do it through AJAX or through constructing and posting a form; on the server side, you can use curl, or a library. You did not say what you want to use it for (and where you want to use it), so you just get the general answer, I'm afraid.
EDIT: Here is the JavaScript semi-solution. You have to already be on some page (i.e. can't use it on _blank), and I'm not sure if it works on all browsers.
javascript:d=document;f=d.createElement("form");h=d.createElement("input");f.setAttribute("method","post");f.setAttribute("enctype","application/x-www-form-urlencoded");f.setAttribute("action","http://www.torec.net/ssearch.asp");h.setAttribute("type","hidden");h.setAttribute("name","search");h.setAttribute("value","query");f.appendChild(h);d.body.appendChild(f);f.submit();

Edit: It is not possible to create a link directly to the first page. However, you can easily send a user to the first page by by creating a form:
<form id="postForm" method="post" action="http://www.example.com/search">
<input type="text" name="search" value="q">
</form>
And then submitting the form whenever the user clicks a psuedo-link:
document.getElementById("postForm").submit();
This can also be done by typing JavaScript code into the address bar:
javascript:a=document.createElement("form");a.method="POST";a.action="http://www.torec.net/‌​ssearch.asp?search=dark&page=2";i=document.createElement("input");i.name="search";i.value="q";a.appendChild(inpu‌​t);a.submit();

Related

How can I capture URL parameters sent to a google form, and save them to the connected spreadsheet?

I have 2 scripts - one to fire on open trigger, and one to fire on save, I'm not sure which one would work best with function scope etc...
But basically, users are sent to the survey form using a public link, and additional info is added to that link in the form of parameters/queries, such as:
booking=123456
start-at=1429952400
item=1702
I'm trying to have the script save these parameters, or even the entire URL that was used to open the form, preferably on the same row as the survey response, but even if the user doesn't submit the form, I would still like to save the URL as a non-completed survey (hence the on-open and on-save triggers).
I looked into:
function doGet(e) {},
function URL(text) {},
function doPost(e) {},
even console.log(params); and console.log(e);
as well as others and I cannot seem to get access to the URL.
What gives? Should I just code this on my own server and run my own form? I would really like to figure out google scripting but it seems just too cumbersome at this point. Any help or solution would be highly appreciated.
To be clear, I don't think I can use a pre-filled url, because I don't know that parameter values ahead of time, and I don't think you can use hidden fields for pre-filled anyway.
From the question
What gives? Should I just code this on my own server and run my own form? I would really like to figure out google scripting but it seems just too cumbersome at this point. Any help or solution would be highly appreciated.
To be clear, I don't think I can use a pre-filled url, because I don't know that parameter values ahead of time, and I don't think you can use hidden fields for pre-filled anyway.
A prefilled-url could be used to set the answers to all the questions in a Google Form.
Please bear in mind that Google Forms doesn't support hidden questions in the sense of an HTML form does, the way that you could do this is by putting the question on a section that the form response flow never show it but on the prefill view all the sections are displayed.
Regarding using Google Apps Script to handle Google Forms a custom URL query string that is not supported, so if that is a deal-breaker, then you should use other options.
If you like so much Google Apps Script you could use it to create a web application as doGet pass the URL query string / parameters to the server side code and also you could grab them from the client-side code by using the HTML Service.

Analytics - Where do the parameters come from

Google Analytics provides me a list of called links of my website.
I wonder where these requests came from and what they effect.
e.g.
www.mywebsite.com/subpage/?ls=1
www.mywebsite.com/subpage/?q=keyword
www.mywebsite.com/subpage/?q=13123sdd
What does ?ls=1 and ?q=keyworddo? And where do they came from? Especially the keywords
Those are GET parameters, and most commonly they come as a result of posting forms (or just by clicking on links with such URLs).
For (the most well-known) example, if you go to https://www.google.com and enter "test" and press Enter, you will go to a page http://google.com/search?q=test (with likely a bunch of other parameters as well). In a very simplified scenario, it would be because the box where you input your search string is an input element with name="q" contained in a form element with method="GET" action="/search"; when you submit the form (by pressing Enter), the browser will make the url by adding all the parameter to the form's action like this:
action?param1=value1&param2=value2...
or in this case, /search?q=test.
(In Google's specific case, this is not actually what is happening, because of various kinds of JavaScript magic that is normally going on; but that magic in the end does the same thing. But it could: if you turned off JavaScript on Google, then what I described would be exactly what would happen.)
As I said, you can submit that same URL literally, without having to go through a form. For example, you can click directly on this link to find some kittens: https://google.com/search?q=kittens
Parameters submitted with other methods than GET do not appear in URLs, and cannot be submitted merely by clicking a link, only through forms (which also support POST method) or JavaScript (which can submit any kind of method: GET, POST, or other methods not available to forms or links, like PUT, DELETE...)
As to what they do, nothing by themselves. They are interpreted by the www.mywebsite.com server, in any way they want. In Google's case, q is the query to search from, and what they do is give you (hopefully) relevant results to it. In www.mywebsite.com's case? No idea. Could be anything.

Forcing a page to POST

This may be a very unusual question, but basically there's a page on another domain (that I can view, but can't edit/change) that has a button. When that button is clicked it generates some unique keys.
I need to pull those unique keys with my web service (using ASP .NET MVC3) I can get the initial HTML of the page, but how can I force the page to "click" the button so that I can get the values after the POST?
Normally, I'd reuse the code to generate keys myself, but I don't have access to the logic.
I hope this makes sense.
Use e.g. firebug to see what POST parameters are sent with form and then make the same POST from your code.
For this you can use WebRequest or WebClient.
See this SO questions that will help you how to do it:
HTTP request with post
Send POST request in C# like a web page does?
How to simulate browser HTTP POST request and capture result in C#
Then just parse the response with technology of your choice (I would use regular expressions - Regex, or LinqToXml if the response is well formed XML).
Note: Keep in mind that your code will be dependent on some service you are not maintaining. So you can get in problems when the service is unavailable, discontinued or if the format of POSTed form or response will be changed.
This really depends on the technology on the targeted site.
If the page is a simple HTML form then you can easily send a POST. You will need to send the expected data to the POST. Then you can parse the data.
If its not so straight forward you will need to look into ways to automate the click. Check Selenium. Also you might need to employ scrapping if the results page is a mess.

How relative link in href working?

I have a problem relating to relative links in href. To make a long story short, I think an example is the best way to get what's going on.
On tinhte.vn/threads/300021/, it is a discussion forum, to go to the page 2, we click on [2].
I view source code of [2], its content is 2.
If I do not misunderstand about relative links, this will append threads/30021/page-2 after the current link, which is tinhte.vn/threads/30021/, and we have the link like this:
tinhte.vn/threads/300021/threads/300012/page-2
But in practice, when I do in the browser, mine is chrome, the link is:
tinhte.vn/threads/300012/page-2
Anyone please explain why?
Sorry, due to the spam prevention, I cannot post direct link.
Thanks in advance.
The link will correctly go to tinhte.vn/threads/300021/threads/300012/page-2 as you guessed. However, looking at the response from a request to that url we can see that the page redirects to another url. I used web-sniffer to quickly see the raw response from the server.
The interesting part of the response is this:
<input type="hidden" name="redirect" value="/threads/300021/page-2"/>
The browser will react to this and navigate to the specified URL. Hence the observed behaviour.
Read more about redirects here.

jQuery Mobile POST request with multiple pages response

From the documentation, http://jquerymobile.com/test/docs/pages/page-links.html
It's important to note that if you are linking from a mobile page that was loaded via Ajax to a page that contains multiple internal pages, you need to add a rel="external" or data-ajax="false" to the link. This tells the framework to do a full page reload to clear out the Ajax hash in the URL. This is critical because Ajax pages use the hash (#) to track the Ajax history, while multiple internal pages use the hash to indicate internal pages so there will be conflicts in the hash between these two modes.
Now, that seems to only apply to GET requests (i.e. via link elements). However, what is the guideline for POST requests? Right now, for the project I am currently working on, if I make a POST request with response that contains multiple N internal pages (lots of divs with data-role="page" and unique IDs), jQuery mobile only loads the first one it sees, and ignores the rest.
I am pulling my hairs out, not sure what to do to work around this. Is there a way to force jQuery mobile to do to full page reload?
Thanks a bunch in advance!
It turns out that data-ajax will work just fine inside the form tag. i.e
<form action="target.php" method="post" data-ajax="false">...</form>
Previously, I thought I had set data-ajax="false". However, it turns out that with the PHP framework (yii) I use, there is a big difference between "data-ajax" => false and "data-ajax" => "false" (former assigns to boolean type, and later is string type). Anyway, long story short, data-ajax is indeed the solution.

Resources