Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3357980
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:41:51+00:00 2026-05-18T02:41:51+00:00

I am trying to send a SOAP request from a xml file and send

  • 0

I am trying to send a SOAP request from a xml file and send to a SOAP service and then read the response while saving it into a file, using libcurl.

An example request in an xml file is as followed:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:olm="http://127.0.0.1:1090/services/olmDSMN">
   <soapenv:Header/>
   <soapenv:Body>
      <olm:getAllCommercialProducts soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </soapenv:Body>
</soapenv:Envelope>

The libcurl code I’m trying to use to make the read and write is as follows:

#define URL "http://192.168.56.101:8088/olmDSMN"

size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream)
{
    return fwrite(ptr,size,nmeb,stream);
}

size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream)
{
    return fread(ptr,size,nmeb,stream);
}

int sendMessage (char * inFile, char * outFile) {
    //writing to file initially
    FILE * rfp = fopen(inFile, "r");
    if(!rfp) {
        perror("Read File Open:");
//        exit(0);
    }

    FILE * wfp = fopen(outFile, "w+"); //File pointer to write the soap response
    if(!wfp) {
        perror("Write File Open:");
//        exit(0);
    }

    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, URL);
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);  //Reads xml file to be sent via POST operationt
        curl_easy_setopt(curl, CURLOPT_READDATA, rfp); 
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);  //Gets data to be written to file
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp);  //Writes result to file

        res = curl_easy_perform(curl);

        curl_easy_cleanup(curl);

    return 1;
    }
}

At the moment the above does not work. When the function is invoked is just waits(as if waiting on a response that never comes). I’m just learning libcurl, so I’m sure I’ve done many things incorrectly. I’ve really been piecing together a couple different tutorials to get it do what I want it to do. Any assistance would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:41:51+00:00Added an answer on May 18, 2026 at 2:41 am

    Ok, so after a whole load of fiddling and piecing together code from different examples I’ve figured out how to perform the above task. See code below:

    #include <stdio.h>
    #include <string.h>
    #include <curl/curl.h>
    
    #define URL "http://192.168.56.101:8088/olmDSMN"
    
    size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream)
    {
        return fwrite(ptr,size,nmeb,stream);
    }
    
    size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream)
    {
        return fread(ptr,size,nmeb,stream);
    }
    
    int sendMessage (char * inFile, char * outFile) {
        //writing to file initially
        FILE * rfp = fopen(inFile, "r");
        if(!rfp) {
            perror("Read File Open:");
    //        exit(0);
        }
    
        FILE * wfp = fopen(outFile, "w+"); //File pointer to write the soap response
        if(!wfp) {
            perror("Write File Open:");
    //        exit(0);
        }
    
        struct curl_slist *header = NULL;
        header = curl_slist_append (header, "Content-Type:text/xml");
        header = curl_slist_append (header, "SOAPAction: myur1");
        header = curl_slist_append (header, "Transfer-Encoding: chunked");
        header = curl_slist_append (header, "Expect:");
        CURL *curl;
        CURLcode res;
    
        curl = curl_easy_init();
        if(curl) {
            curl_easy_setopt(curl, CURLOPT_URL, URL);
            curl_easy_setopt(curl, CURLOPT_POST, 1L);
            curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);  //Reads xml file to be sent via POST operationt
            curl_easy_setopt(curl, CURLOPT_READDATA, rfp); 
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);  //Gets data to be written to file
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp);  //Writes result to file
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
            curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1);
    //        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
            curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);            
            res = curl_easy_perform(curl);
    
            curl_easy_cleanup(curl);
    
            return 1;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send a SOAP request using SOAPpy as the client. I've found
I'm trying to send a SOAP request to a 3rd party web service. I've
I have been tasked with obtaining a response from a SOAP request, using classic
I am trying to send an HTTP request with the contents of a file
I have been trying to send .png images from iPhone to web service. I
I'm trying to dynamically send a SOAP request to different webservices. Each webservice has
I'm trying to send a simple POST request to a REST web service and
I have been trying to encrypt soap message and send to the server, so
I'm trying to send an email in Java but when I read the body
I am trying to send an email from a site I am building, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.