Submit webform via URL only?

2020-03-24 07:45发布

问题:

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?

回答1:

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();


回答2:

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();