post xml data with XMLHttpRequest - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: post xml data with XMLHttpRequest (/thread-4441.html) |
post xml data with XMLHttpRequest - JuergenS - 08-23-2024 Hi ATOZED, Similar to the example "PostDataDemo", I want to query XML data via a corresponding content handler, but my content handler cannot find the query data. C++ Builder 12 Patch 1 Edition: IntraWeb Ultimate Edition IntraWeb Version: 15.6.3 32-bit Server on 64-bit Windows HTTP Server is active on port: 80 HTTPS Server is active on port: 543 (OpenSSL v1.1.1) In the server controller, the content handler is configured as follows: this->SecurityOptions->HttpMethods << hmGet << hmPost; this->SecurityOptions->ForceAjaxPost = true; TIWMimeTypes::RegisterType(L".xml", L"application/xml; charset=UTF-8", false); THandlers::Add(L"", L"Query.xml", new TIWH_Xml()); The query is made interactively via an XMLHttpRequest object (see appendix). The HTML document is inserted into a frame of the MainForm. The content handler is called correctly but the query data does not arrive: aRequest->HasContent = true aRequest->Files->Count = 0 !!! The test tool specified in "How to simulate a request using Firefox Poster addon.png" (2017) I could unfortunately no longer find it at Mozilla. Is there something wrong with my example ? Does anything else need to be configured ? Regards Juergen RE: post xml data with XMLHttpRequest - joergb - 08-23-2024 Hey Juergen I got nearly the same problem, and I could solve it by reading this thread: https://www.atozed.com/forums/thread-1402.html I add these in ServerController.cpp and it works: void __fastcall TIWServerController::IWServerControllerBaseConfig(TObject *Sender) { TpaypalForm::SetURL("/", "paypalForm"); //RegisterContentType(L"application/xml"); RegisterContentType(L"application/json"); // <--------------------- } Maybe it helps Regards Jörg RE: post xml data with XMLHttpRequest - JuergenS - 08-24-2024 Hi Jörg thanks for the hint. I added the following entry in the Server Controller and it works, the XML content is transferred as a file to the server cache. // Content-Type from IW.Parser.Files.hpp RegisterContentType(L"application/xml"); However, I now have a new problem No matter how I try to read the file content in the content handler I always get an exception. Message: "File ...\cache\01e73j1t0q\ATZFH~UucD5kIPr~szeJN7wnmOoy7W.tmp cannot be opened. The process cannot access the file because it is being used by another process." Regards Juergen RE: post xml data with XMLHttpRequest - joergb - 08-25-2024 I used this code , it's the execute func of the content handler: bool __fastcall TContentPP ::Execute(Iw::Http::Request::THttpRequest* aRequest, Iw::Http::Reply::THttpReply* aReply, const System::UnicodeString aPathname, Iwapplication::TIWApplication* aSession, System::Classes::TStrings* aParams) { bool rc = true; UnicodeString empf; THttpFile *xFile; TFileStream *fs; TStringStream *js; if (aRequest->Files->Count > 0) { xFile = aRequest->Files->Items[0]; fs = new TFileStream(xFile->TempPathName, fmOpenRead | fmShareDenyNone); js = new TStringStream; js->CopyFrom(fs, 0); empf = js->DataString; delete fs; delete js; rc = true; } if (aReply) { aReply->ContentType = MIME_JSON; aReply->Code = 200; aReply->CodeText = "OK"; aReply->WriteString("{\"status\":\"success\"}"); // R?ckgabe eines JSON-Objekts } return rc; } //--------------------------------------------------------------------------- the string "empf" hold the json-reply I wait for. RE: post xml data with XMLHttpRequest - JuergenS - 08-26-2024 I'am using the same code, there must be another reason. RE: post xml data with XMLHttpRequest - joergb - 08-26-2024 hmmmm I don't know the reason ... but maybe you can try a shorter filename . I.e. the component TIWURLWindow comes with a similar error , when trying such a long URI name. Don't know why, but a shorter filename works. RE: post xml data with XMLHttpRequest - MJS@mjs.us - 08-26-2024 I'm not able to test this but what happens if you execute the code below to read the JSON? Code: ... RE: post xml data with XMLHttpRequest - JuergenS - 08-26-2024 I used the following code with the same result: UnicodeString CurXmlStr = TIWTextFileReader::ReadAllText(aRequest->Files->Items[0]->TempPathName); RE: post xml data with XMLHttpRequest - MJS@mjs.us - 08-26-2024 Did this 'aRequest->Files->Items[0]->ReadAllText();' work though? The idea being to use what's built in the THttpFile object and not open it a second time. RE: post xml data with XMLHttpRequest - JuergenS - 08-27-2024 (08-26-2024, 06:10 PM)MJS@mjs.us Wrote: Did this 'aRequest->Files->Items[0]->ReadAllText();' work though? The idea being to use what's built in the THttpFile object and not open it a second time. Worked, thanks a lot ! |