【发布时间】:2021-11-07 19:13:28
【问题描述】:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Net;
using System.IO;
namespace FunctionRestApi
{
public static class Function1
{
[FunctionName("Function1")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("URL_with_client_id_authorization_token");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
log.LogInformation(result);
}
return new OkObjectResult(value: httpWebRequest);
}
}
}
我是天蓝色功能的新手。当我只使用“GET”方法时,此代码有效。但是,如果我想对请求正文数据(即日期范围(start_date 和 end_date)和其他一些 sub_user_id)使用“POST”方法,那么我该怎么做呢?
【问题讨论】:
标签: c# azure-functions http-post