Closed omaralcheikh closed 6 years ago
Actually Im using the spatial anchoring branch but the problem also happens on the master branch.
For string content, the content-type header was not being set. Can you verify the fix in develop/fix-content-type? My VS installation refuses to deploy to a HoloLens and I'm currently not able to verify on device.
It worked i received the request body. However, It is still not setting a custom header. Here is a snippet of what im trying to do.
var buffer = new Uint16Array([1, 2]).buffer;
var xhttp = new XMLHttpRequest();
xhttp.setRequestHeader('customHeaderName', buffer);
When trying to get the header value from the server i get an 'undefined' because it did not find the header.
I don't think HTTP headers can be of binary type. In your example, you are setting the header from a UInt16 array and that is not allowed. If you replace buffer with a string, the custom header is sent:
xhttp.setRequestHeader('customHeaderName', "foo/bar");
Also, setRequestHeader should be called after open has been called.
I tried this with pure javascript and did work. I was able to put the buffer in the header and received it on the server. Anyways the thing is I am trying to send the anchor to a server to be saved and shared between devices. The data i want to send is the anchor buffer along with additional info identifying the buffer in json format. As you mentioned when implementing btoa that the buffer size for anchors are in the megabytes and would be more efficient to send them in binary. So instead of creating a single buffer that includes the anchor buffer and additional info in binary i thought ill send the anchor in the header and the json in the body. Anyways what do you think would be the better approach to achieve this?
It's possible that browsers base64 encode binary data used for custom headers.
A possible solution is to send the JSON as the custom header (stringify, base64 encode then setRequestHeader) and send the anchor data as binary payload.
Thank you Cristi, that's actually a better approach. But now I'm trying to set the content type header to octet stream
xhttp.setRequestHeader('content-type', 'application/octet-stream');
and that's causing an error on line 274 in XmlHttpRequest.cpp
Exception thrown at 0x64D7B67E (HoloJsHost-Vs2017.dll) in ThreeJSApp-Vs2017.exe: 0xC0000005: Access violation reading location 0x00000000.
It turns out that the UWP classes that implement string and buffer HTTP content have some quirks. The string class auto-sets content while the buffer class does not. Furthermore, these classes do not accept any HTTP header, just "content headers" - but it's not clear what those are since they're not defined officially.
Long story short, I've pushed a fix for setting content type on binary content. It also works for setting type on string content or no content. The bellow snippet should work:
var r = new XMLHttpRequest();
r.open("post", "http://httpbin.org/post");
var headerData = { someValue: 1 };
r.setRequestHeader('customHeaderName', JSON.stringify(headerData));
var buffer = new Uint16Array([1, 2]).buffer;
r.setRequestHeader('content-type', 'application/binary');
r.send(buffer);
Thank you Cristi. It works great. Please note that i had to set the content-type to "application/octet-stream" instead of "binary" for the buffer to be sent in the body. Can you please merge this branch and spatial anchoring branch to master?
I merged both branches.
Thank you @omaralcheikh for your help!
Hello,
It seems that request headers are not being set when sending a request to the server. This used to work fine prior to the websocket implementation.
Cheers, Omar.