curl-library
Server gives 404 error on curl_easy_send()
Date: Mon, 2 Jul 2012 03:01:27 -0700
Hi
I am trying to send POST request to a web server using curl_easy_send().
However, I see the "404 error" on the server side. My request is reaching
the server but server is not able to understand the request.
The code works fine when I just call curl_easy_perform() (without
CONNECT_ONLY option)
I am not able to understand why my requests are successful on
curl_easy_perform() but not on curl_easy_send().
Appreciate your help. Below is the same code
Thanks
Sam
I am using curl 7.24.0
struct curl_slist *headers=NULL;
CURL *curl;
char request_msg_body[5000];
curl_socket_t sockfd; /* socket */
long sockextr;
size_t iolen;
strcpy(request_msg_body, "POST /sr HTTP/1.1\r\n");
strcat(request_msg_body, "Host: 172.27.52.135:8111\r\n");
strcat(request_msg_body, "Accept: application/json\r\n");
strcat(request_msg_body, "Content-Type: application/json;
charset=utf-8\r\n");
strcat(request_msg_body, "Expect: \r\n\r\n");
strcat(request_msg_body, "test");
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url); //has to URL information to
send POST request to
#if 0 //uncommented when doing just curl_easy_perform()
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json;
charset=utf-8");
headers = curl_slist_append(headers, "Expect: ");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the
cookie engine */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); // needed to set
Content-Type to "application/json" rather than the default
"application/x-www-form-urlencoded"
curl_easy_setopt(curl, CURLOPT_POST, 1); /* specify that this request
is a HTTP POST */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
(*ctx)->post_req.body.memory); /* Specify the content of the request
(XML) */
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, memwrite_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &(*ctx)->post_resp.hdr);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memwrite_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &(*ctx)->post_resp.body);
#endif
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); //need only when doing
curl_easy_send - like in this case
CURLcode res = curl_easy_perform(curl); //Un-commenting the above code,
this without the CONNECT_ONLY option works fine.
if (res != CURLE_OK) {
printf("DE: Curl perform failed: %s\n", curl_easy_strerror(res));
return -1;
}
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
if(CURLE_OK != res)
{
printf("Error: %s\n", curl_easy_strerror(res));
return -1;
}
sockfd = sockextr;
res = curl_easy_send(curl, request_msg_body, strlen(request_msg_body),
&iolen);
if(CURLE_OK != res)
{
printf("Error: %s\n", curl_easy_strerror(res));
return -1;
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-02