From: curl-library [mailto:[email protected]] On Behalf Of 
Fitzgerald, Kevin
Sent: Monday, July 20, 2015 10:30 AM
To: Ray Satiro <[email protected]>; libcurl development 
<[email protected]>
Subject: RE: CURL custom POST commands

On 7/17/2015 2:40 PM, Fitzgerald, Kevin wrote:
Thank you for the example. But I think I am not going about this correctly. 
What I actually need to be able to do is connect to a web service (which it 
appears I am able to do), and send it a POST request. Below is an example of 
the request that I am sending. I think I really just need a curl option that 
will simply send the request to the web service. Any thoughts, can this be done 
(I’m hoping!)?

Again, thanks.

POST /licensecertificationext/service/licensecertification.asmx HTTP/1.1
Host: acc.dwd.wisconsin.gov
Connection: keep-alive
Authorization: Basic – an encrypted username and password here
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Content-Type: text/xml; charset=utf-8
Content-Length:  767

SOAPAction:"http://workweb.dwd.state.wi.us/KIDS/LicenseCertification/Service/checkCertifications";<http://workweb.dwd.state.wi.us/KIDS/LicenseCertification/Service/checkCertifications>

Please don't top post it makes the conversation harder to follow. This is what 
it would look like, all one line:

curl -u user:pass --data-binary @soapreq.xml -H "Content-Type: text/xml; 
charset=utf-8" -H "SOAPAction: 
\"https://workweb.dwd.state.wi.us/KIDS/LicenseCertification/Service/checkCertifications\";<https://workweb.dwd.state.wi.us/KIDS/LicenseCertification/Service/checkCertifications/>"
 
https://acc.dwd.wisconsin.gov/licensecertificationext/service/licensecertification.asmx

Put your XML in soapreq.xml. Note I changed both urls to https, which I 
strongly recommend you use for something like this if it's accepted, even if 
it's not yet mandatory. In the XML I'd change the 'checkCertifications xmlns' 
url to https as well.

Sorry about the top posting. Thanks for this, but it looks like a command line 
request. What I need to do is send my POST within a C program in a UNIX 
environment. I was not clear on that. I guess what need to be able to do using 
the CURL commands in C, is set up an HTTP socket that allows me to send the 
custom request to the web service and receive a response. I have tried 
different things but CURL is creating its own POST command that is rejected by 
the web service as unauthorized (401), because it is password protected, so the 
web service never actually sees my custom POST request. What I am looking for 
is an example of a C program that does something like what I am trying to do, 
as I am new to CURL and am trying to figure things out on the fly.

Thanks,  Kevin

Hello again, I have decided to try a different tack and I am using the sendrecv 
example from the site. Everything seems to work as I need it to, but I am 
getting an Internal Server Error back from the server.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope 
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text
 xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable 
to process request. ---&gt; System.Xml.XmlException: Data at the root level is 
invalid. Line 1, position 1.

I think I am getting this error because of a byte-order mark (BOM) that is 
being added to the HTTP. The data being sent is correct for the web services 
request. Is there a curl option to remove this from the request when using 
culr_easy_send? Any help would be appreciated. Below is the code:
            curl = curl_easy_init();
            if(curl)
            {
              const char *request = full_msg;
              curl_socket_t sockfd; /* socket */
              long sockextr;
              size_t iolen;
              curl_off_t nread;

               printf("\n\n\nYou are using libcurl/%s\n\n\n", 
curl_version_info(CURLVERSION_NOW)->version);

               curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

               /* specify target URL */
               curl_easy_setopt(curl, CURLOPT_URL, url);

               curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);

               curl_easy_setopt(curl, CURLOPT_LOCALPORT, dcf_port);

               curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
               res = curl_easy_perform(curl);

               if(CURLE_OK != res)
               {
                   printf("Error: %s\n", strerror(res));
                   return 1;
               }

               /* Extract the socket from the curl handle - we'll need it for 
waiting.
                * Note that this API takes a pointer to a 'long' while we use
                * curl_socket_t for sockets otherwise.
               */
               res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);

               if(CURLE_OK != res)
               {
                   printf("Error: %s\n", curl_easy_strerror(res));
                   return 1;
               }

               sockfd = sockextr;

               /* wait for the socket to become ready for sending */
               if(!wait_on_socket(sockfd, 0, 60000L))
               {
                   printf("Error: timeout.\n");
                   return 1;
               }
               puts("Sending request.");
               /* Send the request. Real applications should check the iolen
               * to see if all the request has been sent */
               res = curl_easy_send(curl, request, strlen(request), &iolen);

               if(CURLE_OK != res)
               {
                  printf("Error: %s\n", curl_easy_strerror(res));
                  return 1;
               }

               /* read the response */
               for(;;)
               {
                  wait_on_socket(sockfd, 1, 60000L);
                  res = curl_easy_recv(curl, s2, BUF_SZ9, &iolen);

                  fprintf(stdout, "message recieved is %s\n", s2);

                  if(CURLE_OK != res)
                    break;

                  nread = (curl_off_t)iolen;
                  printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n", 
nread);
               }


               /* always cleanup */
               curl_easy_cleanup(curl);

            }

Thanks again…..

Kevin
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to