首页 文章

使用Azure功能的Microsoft Flow随机化一系列数字

提问于
浏览
1

在Flow和SharePoint中,请求将是一个Azure函数 accept the 2 numbers, randomize them, and return one number in between first number and second number.

目标是编写Azure功能并提供所需的URI和其他信息 . 这是流,HTTP Web请求是调用Azure函数的位置 .

enter image description here

1 回答

  • 2

    使用HTTP触发器创建新的C#函数 . 用类似的东西替换代码

    using System.Net;
    
    public static HttpResponseMessage Run(HttpRequestMessage req)
    {
        var v1 = ParseInt(req, "v1");
        var v2 = ParseInt(req, "v2");
    
        return !v1.HasValue || !v2.HasValue
            ? req.CreateResponse(HttpStatusCode.BadRequest, "Params missing")
            : req.CreateResponse(HttpStatusCode.OK, new Random().Next(v1.Value, v2.Value));
    }
    
    private static int? ParseInt(HttpRequestMessage req, string name)
    {
        string s = req.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, name, true) == 0)
            .Value;
        return int.TryParse(s, out int v) ? (int?)v : null;
    }
    

    然后通过URL调用它

    https://{yourapp}.azurewebsites.net/api/{yourfunction}?code={code}&v1={min}&v2={max}
    

相关问题