簡體   English   中英

我如何通過Ajax訪問Deliciouspie身份驗證Web服務

[英]How, can i access tastypie authenticate webservice through ajax

我正在嘗試通過Ajax訪問以下Web服務,但無法正常工作。 http://task.woo.gy/api/v1/article/?format=json用戶名:-超級用戶密碼:-rohit

Ajax功能

  $.ajax({
        type: "POST",
        url: "http://task.woo.gy/api/v1/article/?format=json",
        data: "{ 'username': 'root', 'password': 'rohit'}",
        contentType: "application/json; charset=utf-8",
        success: ajaxCallSucceed_allorder,
        dataType: "json",
        failure: ajaxCallFailed_allorder
    });
 function ajaxCallSucceed_allorder()
 {
  alert('success');
 }
 function ajaxCallFailed_allorder()
 {
  alert('failed');
 }

讓我們先不通過互聯網發送明文形式的用戶名和密碼。 Tastypie具有API密鑰身份驗證機制,可讓您使用用戶和API密鑰(無密碼)登錄。 有一種方法可以自動為新用戶創建API密鑰,我相信有一種管理命令可以為現有用戶創建密鑰。

至於Ajax調用。 在URL中將用戶名和密鑰作為get參數傳遞,或使用授權標頭。 對於后一種選項,您可以使用:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Authorization: ApiKey <username>:<api_key>");

},

混合使用: https//stackoverflow.com/a/5507289以及如何為好吃的東西設置授權標頭?

暫無
暫無

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

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