-1

I'm trying to test the example of the Titanium Proxy Server. However, after copying the example within the 'Read Me' section exactly, I am stuck with an error I can't resolve.

Within this method:

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;
    }
}

I am getting errors for the lines await e.SetRequestBodyString(bodyString); and await e.SetRequestBody(bodyBytes);.

There error message states Cannot await 'void' and it is referring to the parameter within the method SessionEventArgs as a void method itself.

How do I resolve this? Am I doing something wrong as the example code is specifically as written above?

Explorex
  • 547
  • 6
  • 13
  • 1
    Just try to remove await for Set calls.They don't seem to be async. – Dmytro Mukalov Sep 28 '18 at 06:28
  • Possible duplicate of [Getting a Cannot await void, on a method that I have want to await on](https://stackoverflow.com/questions/42233787/getting-a-cannot-await-void-on-a-method-that-i-have-want-to-await-on) – Access Denied Sep 28 '18 at 06:30
  • They changed their API and now it's sync. In previous versions it was async. Install 3.0.8 for example. – Access Denied Sep 28 '18 at 06:32

1 Answers1

0

Their doc is incorrect. It was async (SetRequestBody, SetRequestBodyString), but now it's sync and you get exception like 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;
    }
}
Access Denied
  • 8,723
  • 4
  • 42
  • 72