Azure功能发布问题 [英] Azure functions post issue
本文介绍了Azure功能发布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i我正在使用VS 2017 15.4并在本地运行helloworld功能应用程序。我能够获得关于此功能的请求但是当我在同一个uri上执行发布时它会给出。
mscorlib:执行函数时出现异常:HelloWorld。 System.Net.Http.Formatting:没有MediaTypeFormatter可用于从媒体类型为'application / octet-stream'的内容中读取'Object'类型的对象。
你可以帮我吗
[使用functionName("的HelloWorld")]
公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Function,"获得","交" ;,路线= NULL)] HttpRequestMessage REQ ,TraceWriter log)
{
log.Info(" C#HTTP触发函数处理请求。);
//解析查询参数
字符串名称= req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key," name",true)== 0)
.Value;
//获取请求正文
* dynamic data = await req.Content.ReadAsAsync< object>(); *
//将名称设置为查询字符串或正文数据
name = name ?? data?.name;
return name == null
?req.CreateResponse(HttpStatusCode.BadRequest,"请在查询字符串或请求正文中传递名称" ;)
:req.CreateResponse(HttpStatusCode.OK," Hello" + na我);
}。
解决方案
你必须在你的请求的标题中设置,Content-Type = 应用/ JSON
i am using VS 2017 15.4 and running helloworld function app on local. i was able to do get request on this function but when i perform post on same uri it gives.
mscorlib: Exception while executing function: HelloWorld. System.Net.Http.Formatting: No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'application/octet-stream'.
can you help me with that
[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);
}.
解决方案
You have to set in the headers of your request, Content-Type=application/json
这篇关于Azure功能发布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文