在使用curl post这段数据
"<?xml version=\"1.0\" encoding=\"GB2312\"?><gpsReport><gps><lat>22.541724</lat><long>113.948769</long><speed>0</speed><direction>1</direction><height>200</height><distance>100</distance><time>2012-05-17 14:09:30</time><satellite>8</satellite><mobile>13242065363</mobile></gps></gpsReport>
是出错,试了好多方法终于有结果了。curl_easy_setopt 顺序问题
要使用curl_easy_setopt(curl,CURLOPT_NOBODY,1);
但又有问题 代码1和代码2不同
curl_easy_setopt(curl,CURLOPT_POST,1);
curl_easy_setopt(curl_handle,CURLOPT_NOBODY,1);
int main(void)
{
CURL *curl;
CURLcode res;
static const char *postthis="<?xml version=\"1.0\" encoding=\"GB2312\"?><gpsReport><gps><lat>22.541724</lat><long>113.948769</long><speed>0</speed><direction>1</direction><height>200</height><distance>100</distance><time>2012-05-17 14:09:30</time><satellite>8</satellite><mobile>13242065363</mobile></gps></gpsReport>";
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:12089/gps.aspx");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
curl_easy_setopt(curl,CURLOPT_POST,1);
curl_easy_setopt(curl,CURLOPT_NOBODY,1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
代码2中两个存在都可以
int main2(int argc, char **argv)
{
CURL *curl_handle;
static const char *postthis="<?xml version=\"1.0\" encoding=\"GB2312\"?><gpsReport><gps><lat>22.541724</lat><long>113.948769</long><speed>0</speed><direction>1</direction><height>200</height><distance>100</distance><time>2012-05-17 14:09:30</time><satellite>8</satellite><mobile>13242065363</mobile></gps></gpsReport>";
curl_global_init(CURL_GLOBAL_ALL);
/* init the curl session */
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://localhost:12089/gps.aspx");
curl_easy_setopt(curl,CURLOPT_POST,1);
curl_easy_setopt(curl_handle,CURLOPT_NOBODY,1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postthis);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
/* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
itself */
/* get it! */
curl_easy_perform(curl_handle);
/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
return 0;
}
curl 中post数据CURLOPT_NOBODY和 curl_easy_setopt 顺序问题