Loading editor/src/webedit_api.cpp +20 −7 Original line number Diff line number Diff line Loading @@ -1569,25 +1569,38 @@ void webedit::Api::handleDeleteConnection(libhttppp::HttpRequest &curreq, // Blog API helper: sends JSON array to blog /api, returns parsed response array json_object *webedit::Api::blogApiCall(const std::string &blogUrl, json_object *requestArray) { std::string apiPath = "/api"; libhttppp::HttpUrl url(blogUrl + apiPath); libhttppp::HttpUrl url(blogUrl + "/api"); libhttppp::HttpClient client(url); client.setTimeout(15); libhttppp::HttpRequest apiReq; apiReq.setRequestType(POSTREQUEST); apiReq.setRequestURL(apiPath); apiReq.setRequestURL(url.getPath()); apiReq.setHeaderData("content-type")->push_back("application/json"); apiReq.setHeaderData("host")->push_back(url.getHost()); const char *bodyStr = json_object_to_json_string_ext(requestArray, JSON_C_TO_STRING_NOSLASHESCAPE); std::vector<char> postData(bodyStr, bodyStr + strlen(bodyStr)); std::vector<char> respData = client.Post(apiReq, postData); if (respData.empty()) { // Return a JSON error object instead of null json_object *err = json_object_new_object(); json_object_object_add(err, "error", json_object_new_string("Empty response from server")); return err; } std::string respStr(respData.begin(), respData.end()); return json_tokener_parse(respStr.c_str()); json_object *parsed = json_tokener_parse(respStr.c_str()); if (!parsed) { // Response is not valid JSON — wrap raw text in error object json_object *err = json_object_new_object(); std::string preview = respStr.substr(0, 200); json_object_object_add(err, "error", json_object_new_string(("Not JSON: " + preview).c_str())); return err; } return parsed; } void webedit::Api::handleConnectToConnection(libhttppp::HttpRequest &curreq, Loading Loading
editor/src/webedit_api.cpp +20 −7 Original line number Diff line number Diff line Loading @@ -1569,25 +1569,38 @@ void webedit::Api::handleDeleteConnection(libhttppp::HttpRequest &curreq, // Blog API helper: sends JSON array to blog /api, returns parsed response array json_object *webedit::Api::blogApiCall(const std::string &blogUrl, json_object *requestArray) { std::string apiPath = "/api"; libhttppp::HttpUrl url(blogUrl + apiPath); libhttppp::HttpUrl url(blogUrl + "/api"); libhttppp::HttpClient client(url); client.setTimeout(15); libhttppp::HttpRequest apiReq; apiReq.setRequestType(POSTREQUEST); apiReq.setRequestURL(apiPath); apiReq.setRequestURL(url.getPath()); apiReq.setHeaderData("content-type")->push_back("application/json"); apiReq.setHeaderData("host")->push_back(url.getHost()); const char *bodyStr = json_object_to_json_string_ext(requestArray, JSON_C_TO_STRING_NOSLASHESCAPE); std::vector<char> postData(bodyStr, bodyStr + strlen(bodyStr)); std::vector<char> respData = client.Post(apiReq, postData); if (respData.empty()) { // Return a JSON error object instead of null json_object *err = json_object_new_object(); json_object_object_add(err, "error", json_object_new_string("Empty response from server")); return err; } std::string respStr(respData.begin(), respData.end()); return json_tokener_parse(respStr.c_str()); json_object *parsed = json_tokener_parse(respStr.c_str()); if (!parsed) { // Response is not valid JSON — wrap raw text in error object json_object *err = json_object_new_object(); std::string preview = respStr.substr(0, 200); json_object_object_add(err, "error", json_object_new_string(("Not JSON: " + preview).c_str())); return err; } return parsed; } void webedit::Api::handleConnectToConnection(libhttppp::HttpRequest &curreq, Loading