title: Using an Azure Web Function to receive a Twilio SMS Message
body: <p>I'm trying to get an Azure Web Function to receive a Twilio SMS message - and failing!</p>
  
  <p>I've created a Web Function to successfully send SMS messages - now I want to listen and react to responses.</p>
  
  <p>I've set up a web function as per the below.  Its pretty simple at the moment, and is supposed to parrot back the original message:</p>
  
  <pre><code>public static async Task&lt;HttpResponseMessage&gt; Run(HttpRequestMessage req, TraceWriter log)
          {
              log.Info("C# HTTP trigger function processed a request.");
  
              var data = await req.Content.ReadAsStringAsync();
              var formValues = data.Split('&amp;')
                  .Select(value =&gt; value.Split('='))
                  .ToDictionary(pair =&gt; Uri.UnescapeDataString(pair[0]).Replace("+", " "),
                                pair =&gt; Uri.UnescapeDataString(pair[1]).Replace("+", " "));
  
              // Perform calculations, API lookups, etc. here
  
              var response = new MessagingResponse()
                  .Message($"You said: {formValues["Body"]}");
              var twiml = response.ToString();
              twiml = twiml.Replace("utf-16", "utf-8");
  
              return new HttpResponseMessage
              {
                  Content = new StringContent(twiml, Encoding.UTF8, "application/xml")
              };
          }
  </code></pre>
  
  <p>In Twilio, I've configured the phone to use web hooks:</p>
  
  <p><a href="https://i.stack.imgur.com/CZbjt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CZbjt.png" alt="enter image description here"></a></p>
  
  <p>I've deployed the Web Function, however when I try testing by sending a message, I get the following error in the Twilio logs:</p>
  
  <p>11200 There was a failure attempting to retrieve the contents of this URL
  Msg Unsupported Media Type
  Message: The WebHook request must contain an entity body formatted as JSON.</p>
  
  <p>Does anyone have any experience in how to fix this error?</p>