Created
September 12, 2019 19:45
-
-
Save fernandoc1/d4f60f8926bc9b334ce8925ac5f7ed06 to your computer and use it in GitHub Desktop.
This code tests CGI with C++ and javascript fetch function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
</body> | |
</html> | |
<script> | |
async function loadData() | |
{ | |
let response = await fetch("http://localhost/path/to/TestCGI.bin", { | |
method: 'POST', | |
body: "Test fernando" | |
}); | |
let data = await response.text(); | |
document.body.innerHTML = data; | |
} | |
loadData(); | |
</script> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <iostream> | |
#include <QString> | |
int main(int argc, char** argv) | |
{ | |
printf("Access-Control-Allow-Origin: *\n"); | |
printf("Content-Type: application/json\n\n"); | |
QByteArray inputData; | |
while(!std::cin.eof()) | |
{ | |
char buffer[1024]; | |
std::cin.read(buffer, sizeof(buffer)); | |
int amountRead = std::cin.gcount(); | |
inputData.append(buffer, amountRead); | |
} | |
printf("{}"); | |
QString inputString(inputData); | |
std::cout << inputString.toStdString() << std::endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment