문제

I'm writing a program that I'd like to be able to compile natively and compile with Emscripten. I need to make synchronous HTTPS requests as part of that program.

How do I do that in C++? The Javascript side makes sense, but I don't know what compiles to the XMLHttpRequest.

도움이 되었습니까?

해결책

There are a few answers to your question:

  1. You can use a few methods in emscripten.h such as emscripten_async_wget
  2. You can write a method in Javascript yourself and call it from C++ https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html

but the kicker is that you can't easily make a synchronous call from XMLHttpRequest and get back binary data. Firefox OS will disallow that if the mime type specifies binary data. However, you can override the mime type and convert the resulting text into a typed array yourself. It's the same technique as the hack in this link.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data?#Receiving_binary_data_in_older_browsers

At first glance this sounds like a perfect solution, but if you are receiving a lot of data back, you will have to convert that character array into a typearray and that is slow.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top