curl-users
Help setting Content-Type
Date: Thu, 21 Apr 2005 17:24:00 -0500
I'm using the CURLOPT_HTTPHEADER approach as given in the docs, however
it doesn't seem to be taking. I've simplified my example to the
following:
#include <stdlib.h>
#include <curl/curl.h>
size_t inDataHandler(void *ptr, size_t size, size_t nmemb, void *stream)
{ // just display it...
printf("inData = %s\n", (char *)ptr);
return (size);
}
int main (int argc, char *argv[])
{
int err;
char v_hostname[64] = "https://our.server.com/morestuff";
char v_ua[64] = "User-Agent: xxxx";
char v_ct[64] = "Content-Type: text/*";
char postbuf[4096] = "<myxml>Just some bogus data</myxml>";
CURL *curlHandle = NULL;
struct curl_slist *curlHeader = NULL;
curl_slist_append(curlHeader, v_ua);
curl_slist_append(curlHeader, v_ct);
curl_global_init(CURL_GLOBAL_WIN32 | CURL_GLOBAL_SSL);
curlHandle = curl_easy_init();
curl_easy_setopt(curlHandle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curlHandle, CURLOPT_URL, v_hostname);
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, (void
*)&inDataHandler);
curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, curlHeader);
curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS, postbuf);
err = curl_easy_perform(curlHandle);
if (err != CURLE_OK)
printf("curl_easy_perform failed, err = %d\n", err);
// Clean up.
curl_slist_free_all(curlHeader);
curl_global_cleanup();
return(0);
}
This will compile and work (e.g. send data and get a response), BUT I'm
not getting the response I'm after, and also the verbose output shows:
"Content-Type: application/x-www-form-urlencoded" and nothing for user
agent, (which wouuld explain the response not being what I'm after).
Somehow my headers are not getting set.
Any ideas?
Thanks,
John
This e-mail is confidential. If you are not the intended recipient, you must not disclose or use the information contained in it. If you have received this e-mail in error, please tell us immediately by return e-mail to Email.Control_at_sentry.com and delete the document.
E-mails containing unprofessional, discourteous or offensive remarks violate Sentry policy. You may report employee violations by forwarding the message to Email.Control_at_sentry.com.
No recipient may use the information in this e-mail in violation of any civil or criminal statute. Sentry disclaims all liability for any unauthorized uses of this e-mail or its contents.
This e-mail constitutes neither an offer nor an acceptance of any offer. No contract may be entered into by a Sentry employee without express approval from an authorized Sentry manager.
Warning: Computer viruses can be transmitted via e-mail. Sentry accepts no liability or responsibility for any damage caused by any virus transmitted with this e-mail.
Received on 2005-04-22