简体   繁体   中英

The HTTP request echo query parameter was not returned as plain text in the response

I am trying to register webHook with my Asp .Net application and get this error:

The HTTP request echo query parameter was not returned as plain text in the response. Please return the echo parameter to verify that the WebHook is working as expected.

function subscribe() {
  var obj = {
    WebHookUri: "http://localhost:15975/api/Temp",
    Secret: "12345678901234567890123456789012",
    Description: "Chill"
  };

  var dsf =  $.ajax({
    type: "POST",
    url: "/api/webhooks/registrations",
    data: JSON.stringify(obj),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data, status) { 
      alert(status); 
    },
    failure: function(errMsg) { 
      alert(errMsg); 
    }
  });
  return false;
}

I found the solution. Although Webhook POST data on your callback uri " http://localhost:15975/api/Temp " but you also need to implement a GET method at that uri. It is to validate if given uri is valid.

[System.Web.Http.HttpPost]
 public IHttpActionResult Post(object data)
  {
       return Ok(new { results = "POST" });
  }

 [System.Web.Http.HttpGet]
  public HttpResponseMessage Get()
  {
       var allUrlKeyValues = Request.GetQueryNameValuePairs();
       var parmVal = allUrlKeyValues.FirstOrDefault(x => x.Key == "echo").Value;
       var resp = new HttpResponseMessage(HttpStatusCode.OK);
       resp.Content = new StringContent(parmVal, System.Text.Encoding.UTF8, "text/plain");
       return resp;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM