我正在尝试测试Titanium Proxy Server的示例。但是,在完全复制“自述”部分中的示例之后,我陷入了无法解决的错误。
在此方法内:
public async Task OnRequest(object sender, SessionEventArgs e)
{
Console.WriteLine(e.WebSession.Request.Url);
var requestHeaders = e.WebSession.Request.Headers;
var method = e.WebSession.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{
byte[] bodyBytes = await e.GetRequestBody();
await e.SetRequestBody(bodyBytes);
string bodyString = await e.GetRequestBodyAsString();
await e.SetRequestBodyString(bodyString);
e.UserData = e.WebSession.Request;
}
}
await e.SetRequestBodyString(bodyString);
和await e.SetRequestBody(bodyBytes);
行出现错误。
错误消息状态为Cannot await 'void'
,并且它将方法SessionEventArgs
中的参数称为void方法本身。
我该如何解决?我在做错什么吗,因为示例代码是上面专门写的?
答案 0 :(得分:0)
他们的文档不正确。它是异步的(SetRequestBody,SetRequestBodyString),但是现在它已同步,并且您会收到类似this的异常。
public async Task OnRequest(object sender, SessionEventArgs e)
{
Console.WriteLine(e.WebSession.Request.Url);
var requestHeaders = e.WebSession.Request.Headers;
var method = e.WebSession.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{
byte[] bodyBytes = await e.GetRequestBody();
e.SetRequestBody(bodyBytes);
string bodyString = await e.GetRequestBodyAsString();
e.SetRequestBodyString(bodyString);
e.UserData = e.WebSession.Request;
}
}