A form in my app has the following:
<form action="/faculty/update/agxzdGFuZHJld3NqaHNyDQsSB0ZhY3VsdHkYBww" method="PUT" accept-charset="utf-8">
However, upon submission the request is treated as a GET and is handled by def get() and not def put(). Any help would be appreciated!
Edit:
Thanks for the responses. If I can't use method="PUT" what is the best way of directed the form the the put() method within my handler class? Should I add another handler within main.py?
HTML v4 and XHTML v1 only support the GET and POST request methods within HTML forms.
On the other hand the GET, POST, PUT and DELETE methods are supported via XMLHttpRequest in all modern browsers.
Related Stack Overflow post:
Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
EDIT:
Further to your update, I think your only options would be:
Use the POST method in your form and handle it through the post() handler.
Use AJAX (XMLHttpRequest) to post your form with JavaScript, using the PUT method.
Use HTML5, but this will not work in Internet Explorer.
Browsers only do GET & POST methods. See if your app's platform can simulate PUT methods via a "method" parameter.
I believe GET and POST are the only valid values on a FORM method attribute.
Related
I'm trying to write a spider that will automatically log in to this website. However, when I try using scrapy.FormRequest.from_response in the shell I get the error:
No <form> element found in <200 https://www.athletic.net/account/login/?ReturnUrl=%2Fdefault.aspx>
I can definitely see the form when I inspect element on the site, but it just did not show up in Scrapy when I tried finding it using response.xpath() either. Is it possible for the form content to be hidden from my spider somehow? If so, how do I fix it?
The form is created using Javascript, it's not part of the static HTML source code. Scrapy does not parse Javascript, thus it cannot be found.
The relevant part of the static HTML (where they inject the form using Javascript) is:
<div ng-controller="AppCtrl as appC" class="m-auto pt-3 pb-5 container" style="max-width: 425px;">
<section ui-view></section>
</div>
To find issues like this, I would either:
compare the source code from "View Source Code" and "Inspect" to each other
browse the web page with a browser without Javascript (when I develop scrapers I usually have one browser with Javascript for research and documentations and another one for checking web pages without Javascript)
In this case, you have to manually create your FormRequest for this web page. I was not able to spot any form of CSRF protection on their form, so it might be as simple as:
FormRequest(url='https://www.athletic.net/account/auth.ashx',
formdata={"e": "foo#example.com", "pw": "secret"})
However, I think you cannot use formdata, but instead they expect you to send JSON. Not sure if FormRequest can handle this, I guess you just want to use a standard Request.
Since they heavily use Javascript on their front end, you cannot use the source code of the page to find these parameters either. Instead, I used the developer console of my browser and checked the request/response that happened when I tried to login with invalid credentials.
This gave me:
General:
Request URL: https://www.athletic.net/account/auth.ashx
[...]
Request Payload:
{e: "foo#example.com", pw: "secret"}
Scrapy has a JsonRequest class to help with posting JSON. See here [https://docs.scrapy.org/en/latest/topics/request-response.html]
So something like the below should work
data = {"password": "pword", "username": "user"}
# JSON POST to API login URL
return JsonRequest(
url=url,
callback=self.after_login,
data=data,
)
Hi I'm new to restfulyii
I'm having a problem with the json response a tag is being prepended
Refer to the code below
(just assume that there are '<>' for the link tag)
<link rel="stylesheet" type="text/css" href="/assets/e5ba1689/srbac.css" />{"success":true,"message":"Record(s) Found","data":{"totalCount":1,"share":[{"id":"0","elementid":"1","type":"video","suid":"1","duid":"5","permissions":"superuser"}]}}
this coming from api/ under GET method and same with other rest verbs
I can't parse my JSON data because of the prepended line.
Please help..
reference:
localhost/api/ - method: GET/POST/PUT/DELETE
Everything is working fine with restful yii except that json response format...
Thanks in advance!
Ohmel Paguirigan
The problem seams to be that YII is not recognizing that your request is an actual Ajax request.
Search in srbac/components/Helper.php for:
if (!Yii::app()->request->isAjaxRequest){
Yii::app()->clientScript->registerCssFile($cssFile);
}
You will notice that SRBAC is checking if your request is an actual Ajax request.
Yoshi on the Yii Forms says that:
yii checks if there is a X-Requested-With HTTP header set (which
should result in an $_SERVER['HTTP_X_REQUESTED_WITH'] server variable)
and whether it contains the string 'XMLHttpRequest'. But this is a
custom header set by most javascript libraries (and so does jQuery).
There are e.g. some proxies which drop these custom headers (mainly
for security reasons) and therefore your application can't recognize
whether it's an ajax request or not. It's not 100% reliable.
Therefore, you must make sure that your javascript library is injecting this Header.
To do this in Javascript, in your app.run
add the following:
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Then, all of y our http requests in angular will send the header yii needs to discern that an AjaxRequest is being sent!
Hope this helps!
The CMIS specification says this about the HTTP response to a submitted HTML form:
In general, the response is not useful for an end-user.
Therefore, clients should redirect the response to a hidden HTML iframe.
The iframe’s onLoad event can be used as an operation status notification.
("client" above means a webpage in a browser)
I don't see how it is possible, in HTML, to "redirect the response to a hidden HTML iframe".
The form can not be inside the hidden iframe, as the form needs to be visible. And if the writers had meant to hide the iframe once the form has been submitted, the wording would have been different.
I wonder why they don't recommend ajax instead, but that is not the question. I want to follow their recommendation, or prove them that their recommendation makes no sense.
Can anyone give me an example of such a form that "redirects the response" to an iframe?
Or an example of what the specification was really trying to say?
Or is it just impossible to achieve?
Ajax only works properly if the application is hosted on the CMIS repository because of the same origin policy.
The hidden frame approach works even if the application is served from a different host.
Here is an example:
<script type="text/javascript">
function createCallback() {
...
}
</script>
<form action="..." method="POST" target="createResult">
...
</form>
<iframe name="createResult" style="display:none;" onload="createCallback()"></iframe>
Here is a complete example:
https://svn.apache.org/repos/asf/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings-war/src/main/webapp/web/index.html
Is it possible to fire off an http DELETE using an html form? I have an app that requires an http delete but when I try posting to it with my form, it tells me the method is not allowed and to try DELETE. Here is my form code:
<form method='delete' action='/groups/dissolve/$org_ID' />
<input class='btn btn-danger' type='submit' value='close group forever' style='font-size:82.5%' />
</form>
I am following instructions I found on this site: http://amundsen.com/examples/put-delete-forms/
When I use the REST client plugin for FireFox and send an http delete, it works. Does not work from the form I wrote above. Help?
Thanks
Nope - you cannot code HTTP verbs like "DELETE" from an HTML 4.x or XHTML form:
Is it possible to trigger an HTTP DELETE request from an HTML form?
A proposal for supporting PUT and DELETE in HTML Forms
(I assume that even thought it isn't possible in straight HTML that you still want to get it done.)
You can do it with a bit of Jquery:
How to send a PUT/DELETE request in jQuery?
Override the submit button's behavior and call your own code to process the delete.
hie
i have a html form and while posting a request to a url i also want to pass crendtials using basic-auth
can anybody please share a code example on how to do that?
You could set the url of the form's action attribute to
http://username:password#www.yourserver.com/somewebpage.html
but I don't think this will work with Internet Explorer. There were some spammers abusing this and Microsoft disabled it.