I have developed a DLL library to send a JSON string via POST to an HTTP and HTTPS website. For example, using Deepl.com to translate texts.
You can also complete and execute any form via POST.
Functions:
- SendNetworkFormFields()
- Syntax:
Code: Select all
Result = SendNetworkFormFields(URL$, Array, ArraySize, @Output$, @ErrorOutput)
- Description: Sends an array with the specified fields to a form of a website via POST.
- Parameter:
- URL$: The destination address of the website where the data is to be sent.
- Array: A string array with the individual fields is sent to the website. Field name and field value must be stored separately.
- ArraySize: Number of elements.
- @Output$: The return value from the website is stored in the string variable.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Example:
Code: Select all
EnableExplicit Global PBEx_Network CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_Network = OpenLibrary(#PB_Any, "PB.Ex_Network_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_Network = OpenLibrary(#PB_Any, "PB.Ex_Network_x64.dll") CompilerEndIf If PBEx_Network Prototype SendNetworkFormFields(URL.p-Unicode, Array, ArraySize, Output, ErrorOutput) Global SendNetworkFormFields.SendNetworkFormFields = GetFunction(PBEx_Network, "SendNetworkFormFields") Prototype SendNetworkJSON(URL.p-Unicode, JSON.p-Unicode, Output, ErrorOutput) Global SendNetworkJSON.SendNetworkJSON = GetFunction(PBEx_Network, "SendNetworkJSON") Define Output$ = Space(100000) Define ErrorOutput$ = Space(1024) Define StartPosition Define EndPosition Dim MyArray.s(3) MyArray(0) = "firstname" MyArray(1) = "Pure" MyArray(2) = "lastname" MyArray(3) = "Basic" SendNetworkFormFields("https://www.w3schools.com/action_page.php", MyArray(), ArraySize(MyArray())+1, @Output$, @ErrorOutput$) StartPosition = FindString(Output$, "<h2>") EndPosition = FindString(Output$, "</div>") Debug Mid(Output$, StartPosition, EndPosition-StartPosition) CloseLibrary(PBEx_Network) EndIf
- Syntax:
- SendNetworkJSON()
- Syntax:
Code: Select all
Result = SendNetworkJSON(URL$, JSON$, @Output$, @ErrorOutput)
- Description: Sends a JSON string to a website via POST.
- Parameter:
- URL$: The destination address of the website where the data is to be sent.
- JSON$: A string in JSON format is sent to the website.
- @Output$: The return value from the website is stored in the string variable.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Example:
Code: Select all
EnableExplicit Global PBEx_Network CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_Network = OpenLibrary(#PB_Any, "PB.Ex_Network_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_Network = OpenLibrary(#PB_Any, "PB.Ex_Network_x64.dll") CompilerEndIf If PBEx_Network Prototype SendNetworkFormFields(URL.p-Unicode, Array, ArraySize, Output, ErrorOutput) Global SendNetworkFormFields.SendNetworkFormFields = GetFunction(PBEx_Network, "SendNetworkFormFields") Prototype SendNetworkJSON(URL.p-Unicode, JSON.p-Unicode, Output, ErrorOutput) Global SendNetworkJSON.SendNetworkJSON = GetFunction(PBEx_Network, "SendNetworkJSON") Define Output$ = Space(1024) Define ErrorOutput$ = Space(1024) Define JSON$ Define CurrentJSON Define Sentence$ = "Hello world" Define FromLang$ = "EN" Define ToLang$ = "DE" JSON$ + ~"{" JSON$ + ~" \"jsonrpc\":\"2.0\"," JSON$ + ~" \"method\":\"LMT_handle_jobs\"," JSON$ + ~" \"params\":{" JSON$ + ~" \"jobs\":[" JSON$ + ~" {" JSON$ + ~" \"kind\":\"Default\"," JSON$ + ~" \"raw_en_sentence\":\"" + Sentence$ + ~"\"" JSON$ + ~" }" JSON$ + ~" ]," JSON$ + ~" \"lang\":{" JSON$ + ~" \"user_preferred_langs\":[" JSON$ + ~" \"EN\"," JSON$ + ~" \"PL\"," JSON$ + ~" \"NL\"" JSON$ + ~" ]," JSON$ + ~" \"source_lang_user_selected\":\"" + FromLang$ + ~"\"," JSON$ + ~" \"target_lang\":\"" + ToLang$ + ~"\"" JSON$ + ~" }," JSON$ + ~" \"priority\":-1" JSON$ + ~" }," JSON$ + ~" \"id\":15" JSON$ + ~"}" SendNetworkJSON("https://www.deepl.com/jsonrpc", JSON$, @Output$, @ErrorOutput$) If ParseJSON(1, Output$) CurrentJSON = JSONValue(1) CurrentJSON = GetJSONMember(CurrentJSON, "result") CurrentJSON = GetJSONMember(CurrentJSON, "translations") CurrentJSON = GetJSONElement(CurrentJSON, 0) CurrentJSON = GetJSONMember(CurrentJSON, "beams") CurrentJSON = GetJSONElement(CurrentJSON, 0) CurrentJSON = GetJSONMember(CurrentJSON, "postprocessed_sentence") Debug GetJSONString(CurrentJSON) EndIf CloseLibrary(PBEx_Network) EndIf
- Syntax:
- Windows XP or higher
- .NET Framework 4 or higher
- Unicode activation (standard from PB 5.50)
No assembly registration with regasm.exe with administrator rights is necessary as with COMatePLUS.
Licence: This DLL file is free of charge and may be used both privately and commercially.
The following copyright texts must be provided:
Download: https://www.rsbasic.de/downloads/downlo ... etwork.zipCopyright © 2019 RSBasic.de
I would be happy to receive feedback, suggestions for improvement, bug reports or requests. If you want to support me, you can also donate me a little something. Thank you