【问题标题】:Sending multiple arguments to triggered Azure webjos向触发的 Azure webjos 发送多个参数
【发布时间】:2016-05-18 19:43:15
【问题描述】:

我正在尝试在触发时向 azure webjob 发送多个参数。根据这个https://github.com/projectkudu/kudu/wiki/WebJobs-API#invoke-a-triggered-job

我可以这样称呼它: POST /api/triggeredwebjobs/{job name}/run?arguments={arguments}

我尝试了几种方法来添加多个参数,例如:

?arguments=1&arguments=2
?arguments[]=1&arguments[]=2
?arguments[0]=1&arguments[1]=2
?arguments={1,2}

等等,我尝试了更多愚蠢的东西,还尝试使用表单数据。似乎都没有工作。我的网络作业只是拿起第一个论点。例如,当我这样做时:

static void Main(string[] args)
{
        Console.WriteLine(args[0]);
        Console.WriteLine(args[1]);
}

第一个适用于上述示例,但随后我得到第二行的异常,说 index out of bounds。有没有办法用多个参数触发 webjob,如果有,我该如何实现?

【问题讨论】:

  • 您尝试过 ?argument=1,2 吗?

标签: c# .net azure azure-webjobs


【解决方案1】:

我认为您正在寻找的金块是:

run?arguments={arg1} {arg2}

一个完整的工作示例应该是这样的:

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://your-app-name.scm.azurewebsites.net/");
    client.DefaultRequestHeaders.Accept.Clear();

    //username and password from Publish Profile, can test via https://your-app-name.scm.azurewebsites.net/basicAuth
    var userName = "$your-app-name";
    var password = "go30T5qqBfl0mv3wzhezrkifrKrPEw78ZieLE0JfwYEZ1yx6wy3hDgygBvbM";

    var encoding = new ASCIIEncoding();
    var authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(encoding.GetBytes(string.Format($"{userName}:{password}"))));
    client.DefaultRequestHeaders.Authorization = authHeader;

    HttpResponseMessage response = await client.PostAsync($"api/triggeredwebjobs/YourTriggeredWebJob/run?arguments={arg1} {arg2}", new StringContent(""));
}

【讨论】:

  • 你用上面的例子,@erincerol 让它工作了吗?
  • 我已尝试上述解决方案,但出现以下错误:“No route registered for '/api/triggeredwebjobs/indexer/run?arguments=update 100'”
【解决方案2】:

参数应该用空格分隔:string arguments = "arg1 arg2 arg3";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2015-02-09
    • 1970-01-01
    • 2010-12-25
    相关资源
    最近更新 更多