通过OData读取数据:如何通过curlRCurl指定身份验证方案?

通过OData读取数据:如何通过curlRCurl指定身份验证方案?,第1张

概述我想通过HTTPS OData连接读取一些数据,数据源需要基本身份验证方案.我熟悉通常的 curl/ RCurl选项(例如username,userpwd和cainfo),但我不确定如何传递身份验证方案信息. 这是一个为另一个应用程序工作的同事的一些C#代码: var bind = new HttpsTransportBindingElement();bind.AuthenticationSch 我想通过httpS OData连接读取一些数据,数据源需要基本身份验证方案.我熟悉通常的 curl/ RCurl选项(例如username,userpwd和cainfo),但我不确定如何传递身份验证方案信息.

这是一个为另一个应用程序工作的同事的一些C#代码:

var bind = new httpsTransportBindingElement();bind.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;

所以我想我需要找出什么RCurl相当于.NET值System.Net.AuthenticationSchemes.Basic将在R / curl世界?

这是我到目前为止提出的:

忽略任何身份验证信息

web_page = getURL(  url = "https://xxxx.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc/path/to/ressource",username = "<username>",userpwd = "*****",cainfo = "inst/ssl/ca-bundle.pem")

这就是我得到的答案(通过谷歌Chrome翻译成德语):

<DOCTYPE HTML PUBliC "- / / W3C / / DTD xhtml 1.0 Strict / / EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml"><head>  <Meta name = "generator" content =  "HTML TIDy for linux/x86 (vers 25 march 2009),see www.w3.org" />  <Title> logon Error Message </ Title>  <Meta http-equiv="Content-Type" content="text/HTML; charset=us-ascii" />  <style type="text/CSS">  / * <! [cdaTA [* /      body {Font-family: tahoma,helvetica,sans-serif; color: # 333333; background-color: # FFFFFF; } Td {Font-family: tahoma,sans-serif; Font-size: 70%; color: # 333333; {H1} H2 {} } P {Font-family: tahoma,sans-serif; color: # 333333; margin-top: 4px; margin-bottom: 4px; ul {} li} {Font-family: tahoma,sans-serif; color: # 33333; margin-top: 4px; Emphasize} {color: # 333333; background-color:. # C8E3FF; padding: 5px;} note {color: # CC6600;. } A {Font-family: tahoma,sans-serif; text-decoration: underline; color: # 336699; } A: visited {color: # 001166; } A: hover {text-decoration: none; }      / *]]> * /  </ Style></ head><body>  <table cellpadding="0" cellspacing="0" border="0" wIDth="100%">    <tr>      <td>        <h1> Login Failed </ h1> <br />        <h2> What happened? </ h2>        <p> Calling the URL        https://my310094.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc/RPCRMQUFU_Q0001queryResults        was aborted due to incorrect credentials. </ p>      </ Td>    </ Tr>    <tr>      <td> </ td>    </ Tr>    <tr>      <td >        <strong> Note </ strong> <br />        <ul>          <li> The application was running in the system KHN. </ li>          <li> The application was for the clIEnt 015 and the user and the          Performed language. </ li>        </ ul>      </ Td>    </ Tr>    <tr>      <td> </ td>    </ Tr>    <tr>      <td>        </ p>        <h2> What can you do? </ h2>        <ul>          <li> Check the indication of the clIEnts,users and          the password for typos. </ li>          <li> If you do not have a user ID,contact          your system administrator. </ li>        </ ul> <br />        <p > error code:        ICF-LE-https-c:015-l:-u:-a:1-c:015-l:-r:0-T:1-C:1-U:8-P:-L:6-X:00163E0746C81EE484C92B972817350C_00163E0746C81EE484C92B969D80750C_1-x:00163E0746C81EE484C92B972817550C</p><br />        <p> http 401 - Unauthorized <br /> </ p>        <p> Your SAP Internet Communication Framework Team </ p>      </ Td>    </ Tr>  </ table></ Body></ HTML>

指定httpauth

基于this post,我尝试了以下内容:

web_page = getURL(  url = "https://xxxx.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc/path/to/ressource",cainfo = "inst/ssl/ca-bundle.pem",httpauth = "CURLAUTH_BASIC")

这一次,答案看起来不同((通过谷歌浏览器从德语翻译):

<DOCTYPE HTML PUBliC "- / / W3C / / DTD xhtml 1.0 Strict / / EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml"><head>  <Meta name = "generator" content =  "HTML TIDy for linux/x86 (vers 25 march 2009),see www.w3.org" />  <Title> logon Error Message </ Title>  <Meta http-equiv="Content-Type" content="text/HTML; charset=us-ascii" />  <style type="text/CSS">/ * <! [cdaTA [* /  body {Font-family: tahoma,sans-serif; text-decoration: underline; color: # 336699; } A: visited {color: # 001166; } A: hover {text-decoration: none; }  / *]]> * /  </ Style></ head><body>  <table cellpadding="0" cellspacing="0" border="0" wIDth="100%">    <tr>      <td>        <h1> Login Failed </ h1> <br />        <h2> What happened? </ h2>        <p> Calling the URL        https://my310094.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc was        aborted due to incorrect credentials. </ p>      </ Td>    </ Tr>    <tr>      <td> </ td>    </ Tr>    <tr>      <td > <strong> Note </ strong> <br />      The application was running in the system KHN. Here were no      Credentials provIDed. </ Td>    </ Tr>    <tr>      <td> </ td>    </ Tr>    <tr>      <td>        </ p>        <h2> What can you do? </ h2>        <ul>          <li> If you do not have a user ID,contact          your system administrator. </ li>        </ ul> <br />        <p > error code:        ICF-LE-https-c:015-l:-u:-a:0-c:015-l:-r:99-T:-C:1-U:-P:-L:6-X:00163E0746C81EE484CA0C65DC12398A_00163E0746C81EE484CA0C65D826798A_1-x:00163E0746C81EE484CA0C65DC12598A</p><br />        <p> http 401 - Unauthorized <br /> </ p>        <p> Your SAP Internet Communication Framework Team </ p>      </ Td>    </ Tr>  </ table></ Body></ HTML>
解决方法 使用httr非常简单:

library(httr)url <- "https://xxxx.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc/path/to/ressource"r <- GET(url,authenticate("<username>","*****","basic"))stop_for_status(r)content(r)

(在httr 0.4中,您将能够删除“basic”,因为基本身份验证现在是默认值)

总结

以上是内存溢出为你收集整理的通过OData读取数据:如何通过curl / RCurl指定身份验证方案?全部内容,希望文章能够帮你解决通过OData读取数据:如何通过curl / RCurl指定身份验证方案?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1025193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存