How does HTTP POST work in Polymer?

RAGHU RAMAN

I want to know how POST calls work in Polymer. I know that I have to use POST calls for sending sensitive information such as user passwords and access tokens. I tried doing this :

<iron-ajax
        id="AjaxPost"
        url="/api/login"
        method="POST"
        content-type="application/x-www-form-urlencoded"
        handle-as="json"
        on-response="_handleAjaxPostResponse"
        on-error="_handleAjaxPostError"
        ></iron-ajax>


this.$.AjaxPost.params = { email: "[email protected]", password: "password" };
this.$.AjaxPost.generateRequest();

But, this will set the parameters in the URL, which can be viewed in the browser console like :

POST http://localhost:8080/api/login?email=abc%40mgail.com&password=password 400 (Bad Request)

The PUT method allows you to set the data in body, which I think is more secure. Now I have 2 questions :

  1. Can we set the body of POST method too? Or setting params is same as setting body?
  2. If that is possible, how should I extract the data in the server side?

PS: We are not using SSL HTTPS connection. Having said that, which method can be incorporated for better security?

Srik

The api document for iron-ajax defines body attribute as below:

body
Object default:
Body content to send with the request, typically used with "POST" requests.
If body is a string it will be sent unmodified.
If Content-Type is set to a value listed below, then the body will be encoded accordingly.

content-type="application/json"
    body is encoded like {"foo":"bar baz","x":1}
content-type="application/x-www-form-urlencoded"
    body is encoded like foo=bar+baz&x=1

Otherwise the body will be passed to the browser unmodified, and it will handle any encoding (e.g. for FormData, Blob, ArrayBuffer).

To send the data as body, you should modify your request as below

<iron-ajax
        id="AjaxPost"
        url="/api/login"
        method="POST"
        content-type="application/json"
        handle-as="json"
        on-response="_handleAjaxPostResponse"
        on-error="_handleAjaxPostError"
        ></iron-ajax>


this.$.AjaxPost.body = { "email": "[email protected]", "password": "password" };
this.$.AjaxPost.generateRequest();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How does data-binding in Polymer work?

From Dev

How to work with HTTP Post in android?

From Dev

HTTP POST does not work after switching DNS

From Dev

HTTP POST does not work after switching DNS

From Dev

How does http://to./ work?

From Dev

How does this HTTP request work?

From Dev

Does Polymer work in PHP files?

From Dev

Does Polymer work in PHP files?

From Dev

HTTP Post from Meteor Server does not work - syntax problems?

From Dev

Http post to server from Android app does not work

From Dev

HTTP Post via Android-Java does not work

From Java

How does HTTP file upload work?

From Dev

Flask HTTP Basicauth - How does it work?

From Dev

How does http://a/%%30%30 work?

From Dev

Xamarin MvvmCross Http Request : How does this work?

From Dev

How does $http.jsonp() work

From Dev

$http and factory - how does this pattern work?

From Dev

How does http/ssh protocol work?

From Dev

Databinding of polymer paper_input does not work

From Dev

my Polymer website does not work on firefox

From Dev

Why does this CodeLab Example in Polymer not work?

From Dev

Databinding of polymer paper_input does not work

From Dev

Pseudo elements on Polymer custom element does not work

From Dev

href to another element does not work in Polymer

From Dev

Does jQuery work well with Polymer 2?

From Dev

Display Grid does not work in Polymer correctly

From Dev

How does http connection pooling work in work in Jersey?

From Dev

media_handle_upload $post_data how does it work

From Dev

How does this snippet work exactly? "pk=request.POST['choice']"