title: Titanium Web Proxy - Can't modify request body
body: <p>I'm having an issue with Titanium Web Proxy. What I want is to change the content of certain websites before I load them in the browser. I've implemented everything and it's working okay, minus the changing content part. Here is that part of the code:</p>
  <pre><code>        public async Task OnRequest(object sender, SessionEventArgs e)
      {
          //Console.WriteLine(e.HttpClient.Request.Url);
  
          // read request headers
          var requestHeaders = e.HttpClient.Request.Headers;
  
          var method = e.HttpClient.Request.Method.ToUpper();
          if ((method == &quot;POST&quot; || method == &quot;PUT&quot; || method == &quot;PATCH&quot;))
          {
              // Get/Set request body bytes
              byte[] bodyBytes = await e.GetRequestBody();
              await Task.Run(() =&gt; e.SetRequestBody(bodyBytes));
  
              // Get/Set request body as string
              string bodyString = await e.GetRequestBodyAsString();
              await Task.Run(() =&gt; e.SetRequestBodyString(bodyString));
  
              // store request 
              // so that you can find it from response handler 
              e.UserData = e.HttpClient.Request;
          }
  
          if(e.HttpClient.Request.RequestUri.AbsoluteUri.Contains(&quot;websiteiwanttochange&quot;))
          {
              byte[] bodyBytes = await e.GetResponseBody();
              e.SetRequestBody(bodyBytes);
              string bodyString = await e.GetResponseBodyAsString();
              e.SetRequestBodyString(bodyString);
              e.UserData = e.WebSession.Request;
  
              Console.WriteLine(&quot;\n\n\n\n\n\n\nTesting\n\n\n\n\n\n&quot;);
              Console.WriteLine(bodyBytes.ToString());
              //Console.WriteLine(bodyString);
          }
  
          // To cancel a request with a custom HTML content
          // Filter URL
          if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains(&quot;google.com&quot;))
          {
              e.Ok(&quot;&lt;!DOCTYPE html&gt;&quot; +
                  &quot;&lt;html&gt;&lt;body&gt;&lt;h1&gt;&quot; +
                  &quot;Website Blocked&quot; +
                  &quot;&lt;/h1&gt;&quot; +
                  &quot;&lt;p&gt;Blocked by titanium web proxy.&lt;/p&gt;&quot; +
                  &quot;&lt;/body&gt;&quot; +
                  &quot;&lt;/html&gt;&quot;);
          }
  
          // Redirect example
          if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains(&quot;wikipedia.org&quot;))
          {
              e.Redirect(&quot;https://www.paypal.com&quot;);
          }
      }
  </code></pre>
  <p>Which is pretty much the example I got from Titanium Web Proxy Github. However, this code never reaches &quot;&quot;\n\n\n\n\n\n\nTesting\n\n\n\n\n\n&quot; although it loads the website properly.</p>
  <p>I've tried to add blocking for that website, like it's for google, it works properly and blocks it.</p>
  <p>Does anyone knows what could be the problem? I'm stuck with this for a while, so any help would be appreciated.</p>
  <p>Content changing is not implemented in this example, I just want to see the content as string, then try to change it.</p>