1

I am trying to connect facebook webhook to asp.net application but I am getting 'The URL couldn't be validated. Response does not match challenge' error.

However I can see the response is correct from my .net application but in facebook it shows with prefix '\ufeff\' Here is the error I am getting

I am sending response to callback url using below code :

        var challenge = Convert.ToString(Request.QueryString["hub.challenge"]);

        var verifyToken = Request.QueryString["hub.verify_token"];


        if (verifyToken == "abcxyz123")
        {

            Response.Write(challenge);
        }

Any help is greatly apprecialted. Thanks

Pravin
  • 29
  • 1
  • 3
  • That’s a BOM, Byte Order Mark. Remove the BOM from your script files, store them as UTF-8 without BOM. – CBroe Aug 07 '17 at 13:31
  • I used new UTF8Encoding(false) to remove BOM from .net application, But this Byte Order Mark is added by PHP when response is being captured by Callback url initated by Facebook. I checked the string it is without BOM. – Pravin Aug 07 '17 at 14:02
  • What, where does PHP come into play here? – CBroe Aug 07 '17 at 14:06
  • We have to set callback url and access token in Facebook.Facebook sends https request to my application.On request above code is executed and facebook receives the string returned in above code : Resonse.write(challenge). Screen shot attached in question is getting on facebook while connecting webhook to my application. I am referring this link : https://developers.facebook.com/docs/marketing-api/guides/lead-ads/quickstart/webhooks-integration Only thing is I want to connect to asp.net application but here it is given in PHP. – Pravin Aug 08 '17 at 06:08
  • Ok, so their example is in PHP ... but what does that have to do with _your_ app? – CBroe Aug 08 '17 at 07:15

1 Answers1

0
    public HttpResponseMessage Webhook()
    {
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new StringContent(System.Web.HttpContext.Current.Request.QueryString["hub.challenge"])
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

        return response;
    }
deype0
  • 147
  • 2
  • 4