心想事成 发表于 2006-9-24 14:19:51

检查http 是否正常的c代码

/*gcc -o http -Wall http.c -lcurl
./002 www.chinaunix.net
这个例子就将html代码保存在了www.chinaunix.net文件中了. */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<string.h>


#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

FILE *fp;//定义FILE类型指针
char info;

size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)//这个函数是为了符合CURLOPT_WRITEFUNCTION, 而构造的
{
   
    memcpy(info,ptr,5);
    return 0;
}

int main(int argc, char *argv[])
{
    CURL *curl;
    while (1)
    {
                memset(info,0,5);
    curl_global_init(CURL_GLOBAL_ALL);
    curl=curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, argv);

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);//CURLOPT_WRITEFUNCTION 将后继的动作交给write_data函数处理
    curl_easy_perform(curl);
   

    if (info== '-') printf ("OK\n");
    curl_easy_cleanup(curl);
    sleep (10);
}
    exit(0);
}




/*
<?php if (!extension_loaded("discuz")) print "skip"; ?>
<?php echo "discuz extension is available"; ?>


*/

loverouter 发表于 2006-9-24 21:18:53

http://www.programfan.com/club/old_showbbs.asp?id=59214
http://bbs.pediy.com/showthread.php?s=&threadid=17849&highlight=%C4%DA%C1%AA%BB%E3%B1%E0
http://bbs.pediy.com/showthread.php?s=&threadid=9943&perpage=15&highlight=%C4%DA%C1%AA%BB%E3%B1%E0&pagenumber=1
http://bbs.pediy.com/showthread.php?s=&threadid=27214&highlight=%C4%DA%C1%AA%BB%E3%B1%E0

[ 本帖最后由 loverouter 于 2006-9-24 21:56 编辑 ]
页: [1]
查看完整版本: 检查http 是否正常的c代码