久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='tHfYf'><tr id='tHfYf'><dt id='tHfYf'><q id='tHfYf'><span id='tHfYf'><b id='tHfYf'><form id='tHfYf'><ins id='tHfYf'></ins><ul id='tHfYf'></ul><sub id='tHfYf'></sub></form><legend id='tHfYf'></legend><bdo id='tHfYf'><pre id='tHfYf'><center id='tHfYf'></center></pre></bdo></b><th id='tHfYf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tHfYf'><tfoot id='tHfYf'></tfoot><dl id='tHfYf'><fieldset id='tHfYf'></fieldset></dl></div>
    <bdo id='tHfYf'></bdo><ul id='tHfYf'></ul>
  • <small id='tHfYf'></small><noframes id='tHfYf'>

        <tfoot id='tHfYf'></tfoot>
      1. <legend id='tHfYf'><style id='tHfYf'><dir id='tHfYf'><q id='tHfYf'></q></dir></style></legend>

        如何在來自 javascript 的 REST API 調用中進行 http 身

        How to make http authentication in REST API call from javascript(如何在來自 javascript 的 REST API 調用中進行 http 身份驗證)
      2. <i id='DLtOR'><tr id='DLtOR'><dt id='DLtOR'><q id='DLtOR'><span id='DLtOR'><b id='DLtOR'><form id='DLtOR'><ins id='DLtOR'></ins><ul id='DLtOR'></ul><sub id='DLtOR'></sub></form><legend id='DLtOR'></legend><bdo id='DLtOR'><pre id='DLtOR'><center id='DLtOR'></center></pre></bdo></b><th id='DLtOR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DLtOR'><tfoot id='DLtOR'></tfoot><dl id='DLtOR'><fieldset id='DLtOR'></fieldset></dl></div>

        <tfoot id='DLtOR'></tfoot>
      3. <small id='DLtOR'></small><noframes id='DLtOR'>

      4. <legend id='DLtOR'><style id='DLtOR'><dir id='DLtOR'><q id='DLtOR'></q></dir></style></legend>

            <bdo id='DLtOR'></bdo><ul id='DLtOR'></ul>
                  <tbody id='DLtOR'></tbody>

                  本文介紹了如何在來自 javascript 的 REST API 調用中進行 http 身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要從 Java 腳本調用 OpenMRS REST API 以從 OpenMRS 獲取數據.下面是我的java腳本代碼:

                  I need to call OpenMRS REST API from Java script to get data from OpenMRS. Below is my java script code:

                      function myfunction(){
                  
                      var xhr = new XMLHttpRequest();
                  
                      xhr.open("GET", "http://localhost:8081/openmrs-standalone/ws/rest/v1/person?q=John", false);
                      xhr.setRequestHeader("Authorization: Basic YWRtaW46QWRtaW4xMjM");
                  
                      xhr.send("");
                      alert(xhr.status);
                  
                      }
                  

                  YWRtaW46QWRtaW4xMjM 是我的 base64 編碼的用戶名:密碼,如 這里.如果我沒有將授權行放入代碼中并使用 Firebug 檢查 Web 應用程序,它會返回預期的 401 未授權狀態.但是,如果我授權,則不會返回任何內容,并且在螢火蟲中我也看不到任何響應.如果我直接在瀏覽器上檢查 URL,頁面會詢問用戶名和密碼,并在提供正確的憑據后,它會正常返回數據.因此,我遇到了一些從應用程序的 java 腳本提供 http 身份驗證的問題.我還考慮了這里解釋的方法,但沒有運氣.誰能幫我從 javascript 授權 http 請求?

                  Where YWRtaW46QWRtaW4xMjM is my base64 coded username:password as explained here. If I do not put the authorization line in the code and check the web app using Firebug, it returns 401 unauthorized status that is expected. But if I put the authorization, nothing is returned and in firebug I do not see any response as well. If I check the URL directly on browser, the page asks for username and password and after giving correct credential, it returns the data normaly. So I am getting some problem of providing the http authentication right from the java script of the app. I have also considered the methods explained here but no luck. Can anyone please help me to authorize the http request right from the javascript?

                  推薦答案

                  這是另一個類似但不同的示例,說明如何為授權目的設置標頭,但使用 JQuery 和 AJAX.

                  Here is another similar but different example of how to set the header for authorization purposes, but instead using JQuery and AJAX.

                  var token = "xyz"
                  var url = "http://localhost:8081/openmrs-standalone/ws/rest/v1/person?q=John"
                  $.ajax({
                      url: url,
                      beforeSend: function(xhr) {
                          xhr.setRequestHeader("Authorization", "Bearer " + token)
                      },
                  
                  })
                  .done(function (data) {
                      $.each(data, function (key, value) {
                          // Do Something
                      })
                  })
                  .fail(function (jqXHR, textStatus) {
                      alert("Error: " + textStatus);
                  })
                  

                  下面也是一個示例,說明如何使用 xhr 而不是 AJAX 獲取訪問令牌.

                  Below is also an example of how you might get an access token using xhr instead of AJAX.

                  var data = "grant_type=password&username=myusername@website.com&password=MyPassword";
                  
                  var xhr = new XMLHttpRequest();
                  xhr.withCredentials = true;
                  
                  xhr.addEventListener("readystatechange", function () {
                      if (this.readyState === 4) {
                         console.log(this.responseText);
                      }
                  });
                  
                  xhr.open("POST", "https://somewebsite.net/token");
                  xhr.setRequestHeader("cache-control", "no-cache");
                  xhr.setRequestHeader("client_id", "4444-4444-44de-4444");
                  
                  xhr.send(data);
                  

                  注意跨站點域請求(如果您請求的令牌不在 localhost 或您當前工作的域中),因為您需要 CORS.如果您確實遇到了跨域問題,請參閱本教程以獲取幫助,并且確保您也啟用了來自 API 的 CORS 請求.

                  Beware of cross-site domain requests(if you're requesting a token that's not on localhost or within the domain that you are currently working in), as you'll need CORS for that. If you do run into a cross-domain issue, see this tutorial for help, and be sure you have enabled CORS requests from the API as well.

                  這篇關于如何在來自 javascript 的 REST API 調用中進行 http 身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                    • <bdo id='hhnUj'></bdo><ul id='hhnUj'></ul>
                    • <i id='hhnUj'><tr id='hhnUj'><dt id='hhnUj'><q id='hhnUj'><span id='hhnUj'><b id='hhnUj'><form id='hhnUj'><ins id='hhnUj'></ins><ul id='hhnUj'></ul><sub id='hhnUj'></sub></form><legend id='hhnUj'></legend><bdo id='hhnUj'><pre id='hhnUj'><center id='hhnUj'></center></pre></bdo></b><th id='hhnUj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hhnUj'><tfoot id='hhnUj'></tfoot><dl id='hhnUj'><fieldset id='hhnUj'></fieldset></dl></div>

                        <tbody id='hhnUj'></tbody>

                        • <small id='hhnUj'></small><noframes id='hhnUj'>

                            <legend id='hhnUj'><style id='hhnUj'><dir id='hhnUj'><q id='hhnUj'></q></dir></style></legend>
                          1. <tfoot id='hhnUj'></tfoot>
                            主站蜘蛛池模板: 中文字幕在线播放第一页 | 亚洲另类视频 | 亚洲午夜精品久久久久久app | 亚洲精品视频在线 | 欧美精品一区三区 | 欧美精品中文 | 亚洲精品一区二区三区丝袜 | 中文字幕免费视频 | 欧美国产视频 | 蜜桃视频一区二区三区 | 色视频网站 | 成年人黄色一级毛片 | 成人欧美一区二区三区在线播放 | 一区二区三区亚洲精品国 | 97国产在线视频 | 久久精品国内 | 99久9 | 精久久久久 | 成人在线a| 国产成人叼嘿视频在线观看 | 澳门永久av免费网站 | 亚洲视频一区在线播放 | 欧美精品在线一区二区三区 | а天堂中文最新一区二区三区 | 欧美日本一区二区 | 亚洲色在线视频 | 国产成人精品一区二区三区四区 | 99在线精品视频 | 欧美激情黄色 | 欧美午夜精品久久久久免费视 | 久久精品视频在线观看 | 亚洲草草视频 | 欧美成人一区二区 | 成人在线精品视频 | 久久天堂 | 日本小视频网站 | 日韩欧美中文字幕在线观看 | 国产操操操| 日韩a | 中文字幕国产 | 欧美日韩毛片 |