msgpack data from the client side with js in a werkzeug environment I sent it as follows.
ninja.coffee
sendMsgPack:(event)=>
event.preventDefault()
arr = $('#hogehogeForm').serializeArray()
data = msgpack.pack(arr)
arrayBinary = new Uint8Array(data)
xhr = new XMLHttpRequest()
xhr.open('POST', '/api/url', true)
xhr.onreadystatechange = ()->
if xhr.readyState is 4 and xhr.status is 200
console.log xhr.responseText
else if xhr.readyState is 4 and xhr.status isnt 200
console.log xhr, "hogehoge"
xhr.setRequestHeader('Content-Type', 'application/x-msgpack; charset=x-user-defined')
xhr.send(arrayBinary.buffer)
tasukete.py
import msgpack
from shimehari import Response, ApplicationController, request
import msgpack
class FooController(ApplicationController):
def __init__(self, name):
ApplicationController.__init__(self, name)
def index(self, *args, **kwargs):
return 'hidebu'
def create(self, *args, **kwargs):
#Let's really look at the header
print msgpack.unpackb(request.data)
return Response('aaa')
$ ({'name': 'name', 'value': 'aaaaa'},)
It seems that msgpack.js has a method called msgpack.upload
.
The method is PUT, or the Content-Type of the request header is ʻapplication / x-www-form-urlencoded`.
I felt something immeasurable, so I used raw XMLHttpRequest for the time being.
ArrayBuffer cannot be sent with jQuery.ajax, so it is useless.
When I set the Content-Type to x-www-form-urlencoded
, I felt that it wasn't the case that the sent data was stored in Request.form
instead of Request.data
in werkzeug. I managed to do it.
At last, I decided to actually send it via WebSocket. Well, I feel that there are many situations where WebSocket cannot be used, but if you brush it up conveniently, it will be useful.
I think there are many places to go, so please let me know if you have any details.
Recommended Posts