hello,
This should work. memReq will have the returned json file in Ascii.
After asking the techTeam.
#include "maxon/network_url.h" // for HTTP_POSTMETHOD and HTTP_POSTDATA
#include "maxon/file_utilities.h"
iferr_scope;
maxon::Url theServer{"http://localhost:8080"_s};
maxon::String postData = "foo=bar&bin=go"_s;
theServer.Set(maxon::URLFLAGS::HTTP_POSTMETHOD, maxon::HTTPMETHOD::POST) iferr_return;
theServer.Set(maxon::URLFLAGS::HTTP_POSTDATA, maxon::CString(postData, maxon::StringEncodings::Utf8())) iferr_return;
maxon::BaseArray<maxon::Char> memReq;
iferr(maxon::FileUtilities::ReadFileToMemory(theServer, memReq))
DiagnosticOutput("@", err);
ApplicationOutput("answer @", memReq);
maxon::String result(memReq);
ApplicationOutput("result @", result);
return maxon::OK;
the simple web server i used this with :
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
import json
import cgi
class Server(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
#self.send_header('Content-type', 'application/json')
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_HEAD(self):
self._set_headers()
# GET sends back a Hello world message
def do_GET(self):
self._set_headers()
self.wfile.write(json.dumps({'hello': 'world', 'received': 'ok'}))
# POST echoes the message adding a JSON field
def do_POST(self):
print 'do post'
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD': 'POST'}
)
print form.getvalue("foo")
print form.getvalue("bin")
# refuse to receive non-json content
if ctype != 'application/x-www-form-urlencoded':
self.send_response(400)
self.end_headers()
print "Can't receive non application/x-www-form-urlencoded content", ctype
return
# send the message back
self._set_headers()
self.wfile.write(json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]))
def run(server_class=HTTPServer, handler_class=Server, port=8080):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd on port %d...' % port
httpd.serve_forever()
if __name__ == "__main__":
run()
Cheers,
Manuel