Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Linux
#include <stdio.h>
#include <curl/curl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <iostream>
using namespace std;
string g_buf = "";
size_t http_callback(void *buffer, size_t size, size_t count, void *user_p)
{
    g_buf += (char*)buffer;
    return size*count;
}
 
int main(void)
{
    CURL *curl;
    CURLcode res;
    struct stat file_info;
    double speed_upload, total_time;
    FILE *fd;
 
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"delete");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,&http_callback);
        curl_easy_setopt(curl, CURLOPT_URL,"http://ucenter.local.ucloud.cn/api/aiotest/test");
        curl_easy_setopt(curl,CURLOPT_POSTFIELDS,"username=huancong&password=doyou");
        res = curl_easy_perform(curl);
        if(res != CURLE_OK) {
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));
 
        }
        else {
            cout<<"receive data:"<<endl<<g_buf<<endl;
        }
        curl_easy_cleanup(curl);
    }
    return 0;
}
 
///////////////////////////////////////////////////////////////////////////////
it always return 400.
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.2.4</center>
</body>
</html>
Posted 6-Nov-12 22:29pm
Comments
Richard MacCutchan at 7-Nov-12 4:14am
   
What is the text of the request you are sending?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

thanks, but i had found out the answer .
change "curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"delete");"
curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"DELETE");
 
thanks for you answer. Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100