I'd like to read some data via a HTTPS OData connection and the data source requires the Basic
authentication scheme. I'm familiar with the usual curl/RCurl options (such as username
, userpwd
and cainfo
), but I'm not sure on how to pass the authentication scheme information.
This is some C# code from a colleague that worked for another application:
var bind = new HttpsTransportBindingElement();
bind.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;
So I guess I need to find out what the RCurl equivalent for the .NET
value System.Net.AuthenticationSchemes.Basic
would be in the R/curl world?
This is what I came up with so far:
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"
)
This is the answer I'm getting (translated from German via Google 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, helvetica, sans-serif; font-size: 70%; color: # 333333; {H1} H2 {} } P {font-family: tahoma, helvetica, sans-serif; color: # 333333; margin-top: 4px; margin-bottom: 4px; Ul {} Li} {font-family: tahoma, helvetica, sans-serif; color: # 33333; margin-top: 4px; Emphasize} {color: # 333333; background-color:. # C8E3FF; padding: 5px;} note {color: # CC6600;. } A {font-family: tahoma, helvetica, 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 class="emphasize">
<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 class="note"> 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
Based on this post, I tried the following:
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",
httpauth = "CURLAUTH_BASIC"
)
This time, the answer looks different ((translated from German via Google 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, helvetica, sans-serif; font-size: 70%; color: # 333333; {H1} H2 {} } P {font-family: tahoma, helvetica, sans-serif; color: # 333333; margin-top: 4px; margin-bottom: 4px; Ul {} Li} {font-family: tahoma, helvetica, sans-serif; color: # 33333; margin-top: 4px; Emphasize} {color: # 333333; background-color:. # C8E3FF; padding: 5px;} note {color: # CC6600;. } A {font-family: tahoma, helvetica, 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 class="emphasize"> <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 class="note"> 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>
This really easy with 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)
(In httr 0.4, you'll be able to drop "basic", since basic auth is now the default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With