Post request to golang server using polymer core-ajax? -


i trying make post request using polymer core-ajax server runnung golang. after lot of search (because new stuff) ended following code. also, request working perfect. post parameters dont understand how pass using core-ajax.

<polymer-element name="register-user" attributes="url">     <template>         <core-ajax id="ajaxsubmit" url="{{url}}" contenttype="application/json" handleas="json" method="post" on-core-response="{{response}}"></core-ajax>         <style type="text/css">         </style>     </template>     <script>     polymer({         buttonlistener: function() {             var data = '{"name":"'+ this.name +'", "email":"'+ this.email +'"}';             this.$.ajaxsubmit.data = data;             this.$.ajaxsubmit.go();             console.log(data);         },         response: function(oldvalue){             console.log(this.response);         }     });     </script> </polymer-element> 

above code returns 500 (internal server error) when make post request using curl i.e

curl -i -h 'content-type: application/json' -d '{"name":"batman",          "email":"batman@gmail.com"}' http://so.me.ip.ad:8080/register 

it works should , returns

http/1.1 200 ok content-type: application/json x-powered-by: go-json-rest date: wed, 29 apr 2015 05:40:15 gmt content-length: 117  {   "id": 3,   "name": "batman",   "email": "batman@gmail.com",   "createdat": "2015-04-29t05:40:15.073491143z" } 

also, have cors middleware set on server i.e

api.use(&rest.corsmiddleware{     rejectnoncorsrequests: false,     originvalidator: func(origin string, request *rest.request) bool {         return origin == "http://0.0.0.0:8000"     },     allowedmethods: []string{"get", "post", "put"},     allowedheaders: []string{         "accept", "content-type", "x-custom-header", "origin"},     accesscontrolallowcredentials: true,     accesscontrolmaxage:           3600, }) 

what doing wrong? feedback of great help! ^.^

edit : here little more info if can help.. screenshot

i think cors red herring. problem may sending data form-encoded , not json. found bug user similar problem.

http/1.1 500 internal server error content-type: application/json x-powered-by: go-json-rest date: fri, 12 dec 2014 04:29:59 gmt content-length: 71  {   "error": "invalid character '\\'' looking beginning of value" } 

perhaps should use .body instead of .data? see this answer.

from polymer documentation:

body: optional raw body content send when method === "post".

example:

<core-ajax method="post" auto url="http://somesite.com"     body='{"foo":1, "bar":2}'> </core-ajax> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -