Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure functions req.Content.ReadAsStringAsync()。从浏览器(但不在Azure门户中)访问时,结果始终返回null_Azure Functions_Azureportal_Httpresponsemessage - Fatal编程技术网

Azure functions req.Content.ReadAsStringAsync()。从浏览器(但不在Azure门户中)访问时,结果始终返回null

Azure functions req.Content.ReadAsStringAsync()。从浏览器(但不在Azure门户中)访问时,结果始终返回null,azure-functions,azureportal,httpresponsemessage,Azure Functions,Azureportal,Httpresponsemessage,下面包含我的完整代码(Azure门户上的Azure功能应用程序)。请特别注意这两条线 var jsonContent=req.Content.ReadAsStringAsync().Result; 日志信息(“jsonContent”+jsonContent); 当我使用右侧面板下方的请求主体测试函数时,jsonContent会按原样打印在日志中。但是,在浏览器中使用函数url,并将其附加&name=azure,则jsonContent为空,如日志所示 //完整代码 #r“Newtonsoft

下面包含我的完整代码(Azure门户上的Azure功能应用程序)。请特别注意这两条线

var jsonContent=req.Content.ReadAsStringAsync().Result;
日志信息(“jsonContent”+jsonContent);

当我使用右侧面板下方的请求主体测试函数时,
jsonContent
会按原样打印在日志中。但是,在浏览器中使用函数url,并将其附加
&name=azure
,则
jsonContent
为空,如日志所示

//完整代码
#r“Newtonsoft.Json”
Net系统;
使用Newtonsoft.Json;
使用系统文本;
使用System.IO;
使用System.Net.Http;
使用System.Net.Http.Header;
使用System.Web;
公共静态异步任务运行(HttpRequestMessage请求,ILogger日志)
{
//这两条线有问题吗???
var jsonContent=req.Content.ReadAsStringAsync().Result;
日志信息(“jsonContent”+jsonContent);
//您可以忽略以下行(与问题无关)
字符串jsonToReturn=“Hello World”;
返回新的HttpResponseMessage(HttpStatusCode.OK){
Content=newstringcontent(jsontoreurn,Encoding.UTF8,“application/json”)
};
}
我试着把线路改成这个,但也没用

var jsonContent=await req.Content.ReadAsStringAsync().Result

这个错误有点像

“string”不包含“GetAwaiter”的定义,并且找不到接受“string”类型的第一个参数的扩展方法“GetAwaiter”(是否缺少using指令或程序集引用?

无论如何,我知道一种解决方法,就是使用
HttpRequest
而不是
HttpRequestMessage
来生成
jsonContent
,但我只是好奇为什么这个案例不起作用


有人能看出我的错误吗?谢谢

当您在浏览器中附加带有
&name=azure
的函数url时,它将name=azure设置为http请求头。因此,如果您想发送带有请求正文的http请求,您可以使用postman来触发Azure函数

这是我的测试:

作为查询追加与使用请求正文不同。您可以像这样在Python中调用函数和请求体(仅举一个示例):

reqBody={
“customerid”:customerid,
“imgdata”:imgdata
}
标题={
“内容类型”:“应用程序/json”,
}
url=”https://xxxxx.azurewebsites.net/api/HTTPTrigger.............."
response=requests.post(url,headers=headers,
data=json.dumps(reqBody))
打印(response.json())

事实上,作为查询追加与使用请求正文有很大不同!谢谢