We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: #378
Workflow支持通过Http代理访问Http(s)服务啦,使用方式与普通Http请求基本一致
std::string url = "https://www.sogou.com/"; std::string proxy = "http://user:[email protected]:port"; // proxy url here WFHttpTask *task = WFTaskFactory::create_http_task(url, proxy, 3, 3, http_callback); task->start();
如上述代码所示,仅需在创建Http任务时传入http proxy的url即可创建一个使用proxy的http任务
user:passwd@
task->get_state() == WFT_STATE_TASK_ERROR && task->get_error() == WFT_ERR_HTTP_PROXY_CONNECT_FAILED
task->get_resp()
一个较为完整的示例如下:
#include <iostream> #include <string> #include "workflow/HttpUtil.h" #include "workflow/WFTaskFactory.h" #include "workflow/WFFacilities.h" using namespace std; using namespace protocol; WFFacilities::WaitGroup wait_group(1); void http_callback(WFHttpTask *task) { int state = task->get_state(); int error = task->get_error(); const char *errstr = WFGlobal::get_error_string(state, error); HttpResponse *resp = task->get_resp(); if (state == WFT_STATE_TASK_ERROR && error == WFT_ERR_HTTP_PROXY_CONNECT_FAILED) { printf("Connect to proxy return non 200\n\n"); printf("%s %s %s\n", resp->get_http_version(), resp->get_status_code(), resp->get_reason_phrase() ); } else if (state != WFT_STATE_SUCCESS) { printf("error: %s\n", errstr); } else { const void *body; size_t size = 0; resp->get_parsed_body(&body, &size); printf("Get response from remote server\n\n"); printf("%s %s %s\n", resp->get_http_version(), resp->get_status_code(), resp->get_reason_phrase() ); string name, value; HttpHeaderCursor resp_cursor(resp); while (resp_cursor.next(name, value)) printf("%s: %s\n", name.c_str(), value.c_str()); printf("\n"); } wait_group.done(); } int main() { string url = "https://www.sogou.com/"; // TODO use a real proxy here std::string proxy = "http://user:[email protected]:port"; WFHttpTask *task; task = WFTaskFactory::create_http_task(url, proxy, 3, 3, http_callback); task->start(); wait_group.wait(); return 0; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
PR: #378
Workflow支持通过Http代理访问Http(s)服务啦,使用方式与普通Http请求基本一致
如上述代码所示,仅需在创建Http任务时传入http proxy的url即可创建一个使用proxy的http任务
user:passwd@
即可task->get_state() == WFT_STATE_TASK_ERROR && task->get_error() == WFT_ERR_HTTP_PROXY_CONNECT_FAILED
的错误,此时proxy返回的内容被放在task->get_resp()
中一个较为完整的示例如下:
The text was updated successfully, but these errors were encountered: