Azure 함수에 새로운 Iam VS 2017 15.4를 사용하고 로컬에서 helloworld 함수 응용 프로그램을 실행 중입니다. 나는이 기능에 대한 요청을받을 수 있었지만, 내가 제공 한 동일한 URI에 대해 게시를 수행 할 수있었습니다.Azure 함수 게시 문제
mscorlib : 함수 실행 중 예외 : HelloWorld. System.Net.Http.Formatting : 미디어 유형이 'application/octet-stream'인 콘텐츠에서 'Object'형식의 개체를 읽을 수있는 MediaTypeFormatter가 없습니다.
대담한 라인이 게시물 요청에서 문제를 일으키는 것을 잊어 버렸다고 나에게 말할 수 있습니까? contentType과 ContentType없이 시도했습니다. 몸과 몸없이.
하늘색 함수에서 요청 본문에있는 Json 객체를 어떻게 파싱 할 수 있습니까? 한 가지 방법은 문자열에서 파싱 한 다음 jsonconvert를 사용하여 deserialize하는 것입니다. valueproviders의 modelbinders 등이 application/json
로 설정하여 HTTP 요청에 Content-Type
헤더를 가정 작동합니다
[FunctionName("HelloWorld")]
public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
*dynamic data = await req.Content.ReadAsAsync<object>();*
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}.
그게 나를 위해 일한 방법은 클래스로 내 json을 구문 분석 할 수 있습니다, 나는 문자열에서 구문 분석하려고 다음 jsonconvert.deserialize를 사용하여 deserialize 자동으로 수행 할 수 있습니다. – Rakesh
'SampleType' 타입의 클래스를 가지고 있다면'req.Content.ReadAsAsync