8000 如何用workflow的httptask 发送一个post请求,来用于访问Restful的服务器 · Issue #356 · sogou/workflow · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

如何用workflow的httptask 发送一个post请求,来用于访问Restful的服务器 #356

New issue

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

Closed
boookc opened this issue May 8, 2021 · 5 comments

Comments

@boookc
Copy link
boookc commented May 8, 2021

如何用workflow的httptask 发送一个post请求,来用于访问Restful的服务器
看例子好像是get方式的请求,暂时在HttpRequest类中没有找到相应的方法
比如用curl命令发一个post请求: curl -X POST http://ip:port/func -F 'file=@"123.jpg"' -F "rotate=true"

@Barenboim
Copy link
Contributor
Barenboim commented May 8, 2021

WFHttpTask *task = create_http_task(...);
task->get_req()->set_method("POST");
如果要读取本地文件,可以配合WFFileIOTask。

@boookc
Copy link
Author
boookc commented May 10, 2021

WFHttpTask *task = create_http_task(...);
task->get_req()->set_method("POST");
如果要读取本地文件,可以配合WFFileIOTask。

大佬,能否帮忙写个读取本地文件,放到httptask post请求中的 简单demo

@Barenboim
Copy link
Contributor
Barenboim commented May 10, 2021

这个很简单啊,你可以参考一下http_file_server这个示例,无非就是在FileIOTask的callback里,创建一个http POST任务。大概长这样:

void http_callback(WFHttpTask *http_task)
{
    free(http_task->user_data);
    // ...
}

void fileio_callback(WFFileIOTask *task)
{
    struct FileIOArgs *args = task->get_args();

    close(args->fd);
    if (task->get_state() != WFT_STATE_SUCCESS)
    {
        free(args->buf);
        return;
    }

    WFHttpTask *http_task = WFTaskFactory::create_http_task(..., http_callback);
    http_task->get_req()->set_method("POST");
    http_task->get_req()->append_output_body_nocopy(args->buf, args->count); /* nocopy */
    http_task->user_data = args->buf; /* To free. */
    **task << http_task; /* equal to: series_of(task)->push_back(http_task); */
}

@Barenboim
Copy link
Contributor

@boookc

@chanchann
Copy link
Contributor

An experiment code: https://github.com/chanchann/workflow_annotation/tree/main/demos/14_restful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0