简体   繁体   English

发出URL请求并在C ++中在后台运行

[英]Making a request for an URL and run in background in c++

I need to run a program in c++ for a long period of time that is making url requests on my site every 12 seconds, which triggers a php script. 我需要长时间在C ++中运行一个程序,该程序每12秒在我的网站上发出一次url请求,这会触发php脚本。 I figured out how to do the running, but every time it's making the "request", the browser pops up. 我想出了如何进行运行,但是每次执行“请求”时,都会弹出浏览器。 You can't do anything while this program is running. 该程序运行时,您无法执行任何操作。 So my question is: can I make the request for the page somehow so the browser didn't pop up? 所以我的问题是:我可以以某种方式发出对该页面的请求,以使浏览器没有弹出吗? (My os is windows). (我的操作系统是Windows)。 That is the c++ function that I'm using: 那就是我正在使用的c ++函数:

 #include <iostream> #include <windows.h> using namespace std; int main() { ShellExecute(NULL, "open", "http://www.google.com/",NULL, NULL, SW_MINIMIZE); return 0; } 

A 3rd party http client with a C++ API like curl should work nicely for what you need. 具有Curl这样的C ++ API的第三方HTTP客户端应该可以很好地满足您的需求。 You can find the documentation on their website . 您可以在他们的网站上找到文档。 Here is some very basic example code to make a URL request. 这是一些非常基本的示例代码,用于发出URL请求。 You could just put it in a loop with a timer. 您可以将其与计时器循环放置。

#include <curl/curl.h>

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM