2017-06-14 97 views

回答

1

你可以使用backcurl >>https://github.com/Taymindis/backcurl,这仅仅只是依赖于基于libcurl的。您可以通过使用bcl::setOpts(....)来随意自定义请求,它适用于非阻止UI请求。

示例代码

// Derived from example/main.cpp 
void doGuiWork() { 
    printf("\r %s --- %d", "Drawing thousand Pieces of Color with count elapsed ", countUI++); 
} 


void doUpdate() { 
bcl::LoopBackFire(); 
} 

void doRunOnUI() { 
bool gui_running = true; 
std::cout << "Game is running thread: "; 
bcl::executeOnUI<std::string>([](bcl::Request * req) -> void { 
    bcl::setOpts(req, CURLOPT_URL , "http://www.google.com", 
    CURLOPT_FOLLOWLOCATION, 1L, 
    CURLOPT_WRITEFUNCTION, &bcl::writeContentCallback, 
    CURLOPT_WRITEDATA, req->dataPtr, 
    CURLOPT_USERAGENT, "libcurl-agent/1.0", 
    CURLOPT_RANGE, "0-200000" 
       ); 
}, [&](bcl::Response * resp) { 
    printf("On UI === %s\n", resp->getBody<std::string>()->c_str()); 
    printf("Done , stop gui running with count ui %d\n", countUI); 
    std::this_thread::sleep_for(std::chrono::milliseconds(500)); 
    gui_running = false; 
}); 

while (gui_running) { 
    doGuiWork(); 
    doUpdate(); 
    std::this_thread::sleep_for(std::chrono::milliseconds(1000/16)); 
} 
} 
+0

谢谢,真的是纯libcurl的,我喜欢它:) – Oktaheta

相关问题