在我的Web浏览器中工作的URL上的Libcurl超时

时间:2011-08-05 15:58:24

标签: c curl https libcurl

我有curl的代码:

size_t write_to_string(void * ptr,size_t size,size_t nmeb,ResponseStruct * res_struct){
    size_t bytes = size*nmeb;
    res_struct->length += bytes;
    res_struct->response = realloc(res_struct->response, res_struct->length);
    strncat(res_struct->response,ptr,bytes);
    return bytes;
}

char * get_url_data(char * url){
    CURLcode res;
    curl_easy_reset(curl);
    if(curl){
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,write_to_string);
        ResponseStruct result;
        result.response = malloc(sizeof(char));
        result.response[0] = '\0';
        result.length = 1;
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
        res = curl_easy_perform(curl);
        if (res) {
            return NULL;
        }
        return result.response;
    }
    return NULL;
}

DateData * get_prices(DateData * prior_prices){
    char * response = get_url_data("https://mtgox.com/api/0/data/getTrades.php");
    char * orig = response;
    if (response) {
        //Stuff here just calculates price data
        errno = 1;
        return new_prices;
    }
    errno = 0;
    return prior_prices;
}

get_prices函数将不断超时,而“http://mtgox.com/api/0/data/getTrades.php”在网络浏览器中正常。

有什么问题?

谢谢!

编辑dtruss输出(注意connect给出错误......):

SYSCALL(args)        = return
__sysctl(0x7FFF5FBFE060, 0x6, 0x0)       = 0 0
__sysctl(0x7FFF5FBFE060, 0x6, 0x10084D400)       = 0 0
kqueue(0x7FFF5FBFE280, 0x0, 0x50)        = 4 0
kevent(0x4, 0x7FFF5FBFE280, 0x1)         = 0 0
socket(0x1, 0x1, 0x0)        = 5 0
setsockopt(0x5, 0xFFFF, 0x1022)      = 0 0
connect_nocancel(0x5, 0x7FFF5FBFE050, 0x6A)      = 0 0
sendto_nocancel(0x5, 0x10013D5F0, 0x1C)      = 28 0
recvfrom_nocancel(0x5, 0x7FFF5FBFE09C, 0x4)      = 4 0
socketpair(0x1, 0x1, 0x0)        = 0 0
sendto_nocancel(0x5, 0x100141C80, 0x33)      = 51 0
sendmsg_nocancel(0x5, 0x7FFF5FBFDFB0, 0x0)       = 1 0
close_nocancel(0x7)      = 0 0
recvfrom_nocancel(0x6, 0x7FFF5FBFDFFC, 0x4)      = 4 0
close_nocancel(0x6)      = 0 0
socketpair(0x1, 0x1, 0x0)        = 0 0
sendto_nocancel(0x5, 0x100141C80, 0x33)      = 51 0
sendmsg_nocancel(0x5, 0x7FFF5FBFDFB0, 0x0)       = 1 0
close_nocancel(0x7)      = 0 0
recvfrom_nocancel(0x6, 0x7FFF5FBFDFFC, 0x4)      = 4 0
close_nocancel(0x6)      = 0 0
kevent(0x4, 0x7FFF5FBFE280, 0x1)         = 0 0
kevent(0x4, 0x0, 0x0)        = 1 0
kevent(0x4, 0x0, 0x0)        = 1 0
recvfrom_nocancel(0x5, 0x7FFF5FBFE0B0, 0x1C)         = 28 0
recvfrom_nocancel(0x5, 0x100141D30, 0x21)        = 33 0
select_nocancel(0x6, 0x7FFF5FBFE030, 0x0)        = 0 0
kevent(0x4, 0x7FFF5FBFDAE0, 0x1)         = 0 0
kevent(0x4, 0x0, 0x0)        = 1 0
kevent(0x4, 0x0, 0x0)        = 0 0
kevent(0x4, 0x0, 0x0)        = 1 0
kevent(0x4, 0x0, 0x0)        = 1 0
recvfrom_nocancel(0x5, 0x7FFF5FBFE0B0, 0x1C)         = 28 0
recvfrom_nocancel(0x5, 0x100141D30, 0x25)        = 37 0
select_nocancel(0x6, 0x7FFF5FBFE030, 0x0)        = 0 0
kevent(0x4, 0x7FFF5FBFDAE0, 0x1)         = 0 0
sendto_nocancel(0x5, 0x100141C90, 0x1C)      = 28 0
sendto_nocancel(0x5, 0x100141C90, 0x1C)      = 28 0
close_nocancel(0x4)      = 0 0
sigaction(0xE, 0x7FFF5FBFE940, 0x0)      = 0 0
setitimer(0x0, 0x7FFF5FBFE940, 0x7FFF5FBFE920)       = 0 0
socket(0x2, 0x1, 0x6)        = 4 0
setsockopt(0x4, 0xFFFF, 0x1022)      = 0 0
fcntl(0x4, 0x3, 0x0)         = 2 0
fcntl(0x4, 0x4, 0x6)         = 0 0
connect(0x4, 0x7FFF5FBFEC20, 0x10)       = -1 Err#36
select(0x5, 0x7FFF5FBFE9C0, 0x7FFF5FBFE940, 0x7FFF5FBFE8C0, 0x7FFF5FBFEA60)  = 1 0
getsockopt(0x4, 0xFFFF, 0x1007)      = 0 0
stat64("/dev/urandom\0", 0x7FFF5FBFE780, 0x0)        = 0 0
open_nocancel("/dev/urandom\0", 0x0, 0x1B6)      = 6 0
read_nocancel(0x6, "\"\247\326\354\001-\250\263\346\377%Kn\222_X\307^3\372Z\370\233\357[\372\376\247\241\022\336\340K\240\211\027S\335qY\255L\320G\205h\"\f^\266\355\336\345sG\315\337>\367\213&Y\264\371\310\357\017\274\367\370ek7\341]\226\322-\004\330\022\325\304%\212`\307\364e\316M\262\367\020LEM\r{\206\335\257\354%\f\307\242\002#\303\307\360\271\357\226\337\351\0", 0x400)      = 1024 0
close_nocancel(0x6)      = 0 0
open("/dev/urandom\0", 0x20004, 0x7FFF5FBFE978)      = 6 0
fstat64(0x6, 0x7FFF5FBFE970, 0x0)        = 0 0
select(0x7, 0x7FFF5FBFEB20, 0x0, 0x0, 0x7FFF5FBFEBA0)        = 1 0
read(0x6, "M\004\343\370\204\020\373\243\351\316X\240o\351!c\306\342\210\345}wcB\220\005{\205\177\016\005c\0", 0x20)         = 32 0
close(0x6)       = 0 0
getuid(0x0, 0x1, 0x0)        = 501 0
write(0x4, "\026\003\001\0", 0x73)       = 115 0
dtrace: error on enabled probe ID 1770 (ID 18656: syscall::read:return): out of scratch space in action #12 at DIF offset 44
select(0x5, 0x7FFF5FBFEBA0, 0x7FFF5FBFEB20, 0x7FFF5FBFEAA0, 0x7FFF5FBFEC40)  = 1 0
read(0x4, "\026\003\001\025'\002\0", 0x7)        = 7 0
read(0x4, "\0", 0x1525)      = 1353 0
dtrace: error on enabled probe ID 1770 (ID 18656: syscall::read:return): out of scratch space in action #12 at DIF offset 44
select(0x5, 0x7FFF5FBFEBA0, 0x7FFF5FBFEB20, 0x7FFF5FBFEAA0, 0x7FFF5FBFEC40)  = 1 0
read(0x4, "crl0\201\216\006\b+\006\001\005\005\a\001\001\004\201\2010\17709\006\b+\006\001\005\005\a0\001\206-http://ocsp.startssl.com/sub/class2/server/ca0B\006\b+\006\001\005\005\a0\002\2066http://aia.startssl.com/certs/sub.class2.server.ca.crt0#\006\003U\035\022\004\0340\032\206\030http://www.startssl.com/0\r\006\t*\206H\206\367\r\001\001\005\005\0", 0xFDC)       = 1360 0
dtrace: error on enabled probe ID 1770 (ID 18656: syscall::read:return): out of scratch space in action #12 at DIF offset 44
select(0x5, 0x7FFF5FBFEBA0, 0x7FFF5FBFEB20, 0x7FFF5FBFEAA0, 0x7FFF5FBFEC40)  = 1 0
read(0x4, "http://crl.startssl.com/sfsca.crl0\201\200\006\003U\035 \004y0w0u\006\v+\006\001\004\001\201\2657\001\002\0010f0.\006\b+\006\001\005\005\a\002\001\026\"http://www.startssl.com/policy.pdf04\006\b+\006\001\005\005\a\002\001\026(http://www.startssl.com/intermediate.pdf0\r\006\t*\206H\206\367\r\001\001\005\005\0", 0xA8C)        = 1360 0
dtrace: error on enabled probe ID 1770 (ID 18656: syscall::read:return): out of scratch space in action #12 at DIF offset 44
select(0x5, 0x7FFF5FBFEBA0, 0x7FFF5FBFEB20, 0x7FFF5FBFEAA0, 0x7FFF5FBFEC40)  = 1 0
read(0x4, "nB\343?\336!>{\341\rp\373c\252\250l\032T\264\\%z\311\242\311\213\026\246\273,~\027^\005MXn\022\035\001\356\022\020\r\3062\177\030\377\374\364\372\315n\221\3506I\276\032Hi\213\302\226M\032\022\262i\027\301\n\220\326\372y\"H\277\272{i\370p\307\372z7\330\330\r\322vOW\377\220\267\343\221\322\335\357\302`\267g:\335\376\252\234\360\324\213\177r\"\316\306\237\227\266\370\257\212\240\020\250\331\373\030\306\266\265\\R<\211\266\031*s\001\n\017\003\263\022`\362z/\201\333\243n\377&0\227\365\213\335\211W\266\255=\263\257+\305\267v\002\360\245\326+\232\206\024*r\366\3433\214]\tK\023\337\273\214t\023RK\002\003\001\0", 0x53C)        = 1340 0
sigaction(0xD, 0x7FFF5FBFEF10, 0x7FFF5FBFEF40)       = 0 0
sigprocmask(0x1, 0x0, 0x7FFF5FBFE950)        = 0x0 0
sigaltstack(0x0, 0x7FFF5FBFE940, 0x0)        = 0 0
sigaction(0xE, 0x0, 0x7FFF5FBFE9C0)      = 0 0
sigaction(0xE, 0x7FFF5FBFE940, 0x0)      = 0 0
setitimer(0x0, 0x7FFF5FBFE940, 0x7FFF5FBFE920)       = 0 0
socket(0x1E, 0x2, 0x0)       = 4 0
close(0x4)       = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
write(0x4, "\026\003\001\001\006\020\0", 0x136)      = 310 0
dtrace: error on enabled probe ID 1770 (ID 18656: syscall::read:return): out of scratch space in action #12 at DIF offset 44
select(0x5, 0x7FFF5FBFEBA0, 0x7FFF5FBFEB20, 0x7FFF5FBFEAA0, 0x7FFF5FBFEC40)  = 1 0
read(0x4, "\024\003\001\0", 0x5)         = 5 0
read(0x4, "\001\0", 0x1)         = 1 0
read(0x4, "\026\003\001\0", 0x5)         = 5 0
read(0x4, "\177\226\217\004\0339\n\233D\216G\257s\240\332x[i\021\247\333f^\325\225=\345.\350XN/\0", 0x20)        = 32 0
write(0x4, "\027\003\001\0", 0x5D)       = 93 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
select(0x5, 0x7FFF5FBFEEA0, 0x7FFF5FBFEE20, 0x7FFF5FBFEDA0, 0x7FFF5FBFEF40)  = 0 0
select(0x5, 0x7FFF5FBFEE00, 0x7FFF5FBFED80, 0x7FFF5FBFED00, 0x7FFF5FBFEEA0)  = 0 0
write(0x4, "\025\003\001\0", 0x17)       = 23 0
close(0x4)       = 0 0
sigaction(0xD, 0x7FFF5FBFEF10, 0x7FFF5FBFEF40)       = 0 0
write_nocancel(0x1, "CURL FAILED WITH ERROR CODE 28\n\0", 0x1F)      = 31 0
write_nocancel(0x1, "ERROR: There has been an error with retrieving the price data. Check connection.\n\0", 0x51)        = 81 0

2 个答案:

答案 0 :(得分:0)

决定使用tradehill的API,因为它有效。

https://api.tradehill.com/APIv1/USD/Trades

感谢omrib和nos。

答案 1 :(得分:0)

MtGox要求您发送用户代理字符串,否则它将不会处理您的请求。不幸的是,这在任何地方都没有记录。

更新您的代码以传递用户代理字符串(只需复制您的浏览器使用的字符串),它应该可以正常工作。