Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 1606:31f4adefb88f
issuing HTTP requests from the plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Sep 2015 17:37:26 +0200 |
parents | fd0464ce1962 |
children | adc6a5704cdb |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Tue Sep 01 16:41:16 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue Sep 01 17:37:26 2015 +0200 @@ -1121,6 +1121,53 @@ } + void OrthancPlugins::CallHttpClient(const void* parameters) + { + const _OrthancPluginCallHttpClient& p = *reinterpret_cast<const _OrthancPluginCallHttpClient*>(parameters); + + HttpClient client; + client.SetUrl(p.url); + + if (p.username != NULL && + p.password != NULL) + { + client.SetCredentials(p.username, p.password); + } + + switch (p.method) + { + case OrthancPluginHttpMethod_Get: + client.SetMethod(HttpMethod_Get); + break; + + case OrthancPluginHttpMethod_Post: + client.SetMethod(HttpMethod_Post); + client.GetBody().assign(p.body, p.bodySize); + break; + + case OrthancPluginHttpMethod_Put: + client.SetMethod(HttpMethod_Put); + client.GetBody().assign(p.body, p.bodySize); + break; + + case OrthancPluginHttpMethod_Delete: + client.SetMethod(HttpMethod_Delete); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + std::string s; + client.ApplyAndThrowException(s); + + if (p.method != OrthancPluginHttpMethod_Delete) + { + CopyToMemoryBuffer(*p.target, s); + } + } + + bool OrthancPlugins::InvokeService(_OrthancPluginService service, const void* parameters) { @@ -1479,6 +1526,10 @@ CompressImage(parameters); return true; + case _OrthancPluginService_CallHttpClient: + CallHttpClient(parameters); + return true; + default: { // This service is unknown to the Orthanc plugin engine