POST from a mapping

Edited 2021/4/8 to reflect curl changes.

 

Add this there you to connect to the WS:

string Response;

Response=CURL_PostFromVariableContent("request MSG", "http://adress:port/");

 

Add this in Custom EDI-C functions(Mappings settings):

 

string CURL_PostFromVariableContent(string dataToUpload, string uploadTargetURL)

{
dynamic cURL;
cURL = createdynamic("ibzcURL");
integer StreamHeader = cURL.stream_open("memory", "ca,w", "");
integer StreamData = cURL.stream_open("memory", "ca,w", "");
integer PostStreamHandle = cURL.stream_open("memory", "r", "memoryStream");
string Header;
integer Status;

cURL.easy_setoption_int("CURLOPT_HEADERDATA", StreamHeader);
cURL.easy_setoption_int("CURLOPT_WRITEDATA", StreamData);
cURL.easy_setoption_str("CURLOPT_URL", uploadTargetURL);
cURL.easy_setoption_int("CURLOPT_POST", 1);
cURL.stream_memory_content_set(PostStreamHandle, dataToUpload);
cURL.easy_setoption_int("CURLOPT_READDATA", PostStreamHandle);


cURL.easy_setoption_int("CURLOPT_SSL_VERIFYPEER", 0); // ignore cert checking

//cURL.easy_setoption_str( "CURLOPT_CAINFO", "cacert.pem") // where to check certs


integer Result = cURL.easy_perform();
if(Result!=0 )
println("CURLError:" & Result & ":" & cURL.easy_strerror(Result));
cURL.easy_getinfo("CURLINFO_RESPONSE_CODE", Status);
cURL.stream_close(PostStreamHandle);
PostStreamHandle = 0;
cURL.stream_memory_content_get(StreamHeader, Header);
cURL.stream_close(StreamHeader);
StreamHeader = 0;
cURL.stream_memory_content_get(StreamData, dataToUpload);
cURL.stream_close(StreamData);
StreamData = 0;
releasedynamic(cURL);
println (Status);
return dataToUpload;

}

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk