簡體   English   中英

HTTP請求回顯查詢參數未在響應中作為純文本返回

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

我試圖用我的Asp .Net應用程序注冊webHook並收到此錯誤:

HTTP請求回顯查詢參數未在響應中作為純文本返回。 請返回echo參數以驗證WebHook是否按預期工作。

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

我找到了解決方案。 盡管Webhook回調uri“ http://localhost:15975/api/Temp ”上的POST數據,但您還需要在該uri上實現GET方法。 這是為了驗證給定的uri是否有效。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM