pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="dtnh7v7" 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="vlb5lxn" 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="l7pdhlh" 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>
                            主站蜘蛛池模板: 合肥仿石砖_合肥pc砖厂家_合肥PC仿石砖_安徽旭坤建材有限公司 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 四川成人高考_四川成考报名网 | 贝朗斯动力商城(BRCPOWER.COM) - 买叉车蓄电池上贝朗斯商城,价格更超值,品质有保障! | 代理记账_免费注册公司_营业执照代办_资质代办-【乐财汇】 | 天津货架厂_穿梭车货架_重型仓储货架_阁楼货架定制-天津钢力仓储货架生产厂家_天津钢力智能仓储装备 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | 干法制粒机_智能干法制粒机_张家港市开创机械制造有限公司 | 手持式浮游菌采样器-全排二级生物安全柜-浙江孚夏医疗科技有限公司 | 冷水机,风冷冷水机,水冷冷水机,螺杆冷水机专业制造商-上海祝松机械有限公司 | 模型公司_模型制作_沙盘模型报价-中国模型网 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 模具钢_高速钢_不锈钢-万利钢金属材料 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 金属管浮子流量计_金属转子流量计厂家-淮安润中仪表科技有限公司 | AGV叉车|无人叉车|AGV智能叉车|AGV搬运车-江西丹巴赫机器人股份有限公司 | 上海洗地机-洗地机厂家-全自动洗地机-手推式洗地机-上海滢皓洗地机 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 塑胶地板-商用PVC地板-pvc地板革-安耐宝pvc塑胶地板厂家 | 庭院灯_太阳能景观灯_草坪灯厂家_仿古壁灯-重庆恒投科技 | 楼梯定制_楼梯设计施工厂家_楼梯扶手安装制作-北京凌步楼梯 | 防火阀、排烟防火阀、电动防火阀产品生产销售商-德州凯亿空调设备有限公司 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 玻璃钢型材_拉挤模具_玻璃钢拉挤设备——滑县康百思 | 珠宝展柜-玻璃精品展柜-首饰珠宝展示柜定制-鸿钛展柜厂家 | 深圳标识制作公司-标识标牌厂家-深圳广告标识制作-玟璟广告-深圳市玟璟广告有限公司 | 精密模具加工制造 - 富东懿 | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | 中医中药治疗血小板减少-石家庄血液病肿瘤门诊部 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 优考试_免费在线考试系统_培训考试系统_题库系统_组卷答题系统_匡优考试 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 北京易通慧公司从事北京网站优化,北京网络推广、网站建设一站式服务商-北京网站优化公司 | ◆大型吹塑加工|吹塑加工|吹塑代加工|吹塑加工厂|吹塑设备|滚塑加工|滚塑代加工-莱力奇塑业有限公司 | 护栏打桩机-打桩机厂家-恒新重工 | 蔬菜配送公司|蔬菜配送中心|食材配送|饭堂配送|食堂配送-首宏公司 |