2016-07-11 13 views
0

Ich habe an einer R-Schnittstelle zu einer HTTP-API mit Digest-Authentifizierung gearbeitet und ich habe ein Problem, in dem die Anfrage funktioniert absolut gut auf meinem nicht funktioniert -Windows-Betriebssysteme, aber ich bekomme immer 401-Status, wenn Sie genau den gleichen Code unter Windows ausführen.RCurl (mit Digest-Authentifizierung) Realm nicht korrekt unter Windows

Ich versuche gerade, es mit RCurl zu tun, aber das gleiche passiert mit HTR, als ich das versuchte.

Auch die API ist leider nicht proprietär, so musste ich alle URLs ändern, sorry.

Auf meinen Nicht-Windows-Betriebssystemen erhalte ich das folgende Verhalten:

rprompt> getURL('http://demo.someapi.net/some/url', userpwd="demo:demo", httpauth=1L, verbose=TRUE) 
* Trying 195.224.16.34... 
* Connected to demo.someapi.net (195.224.16.34) port 443 (#0) 
* TLS 1.0 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 
* Server certificate: *.someapi.net 
* Server certificate: RapidSSL SHA256 CA - G3 
* Server certificate: GeoTrust Global CA 
> GET /some/url HTTP/1.1 
Host: demo.someapi.net 
Accept: */* 

< HTTP/1.1 401 Unauthorized 
< Cache-Control: no-cache 
< Content-Type: text/html 
< Server: Microsoft-IIS/7.5 
< WWW-Authenticate: Digest realm="company.product", nonce="MTEvMDcvMjAxNiAwODo0NTozMw", opaque="0000000000000000", stale=false, algorithm=MD5, qop="auth" 
< X-Powered-By: ASP.NET 
< Date: Mon, 11 Jul 2016 08:44:33 GMT 
< Content-Length: 1293 
< 
* Ignoring the response-body 
* Connection #0 to host demo.someapi.net left intact 
* Issue another request to this URL: 'https://demo.someapi.net/some/url' 
* Found bundle for host demo.someapi.net: 0x7f96c8d55af0 
* Re-using existing connection! (#0) with host demo.someapi.net 
* Connected to demo.someapi.net (195.224.16.34) port 443 (#0) 
* Server auth using Digest with user 'demo' 
> GET /some/url HTTP/1.1 
Host: demo.someapi.net 
Authorization: Digest username="demo", realm="company.product", nonce="MTEvMDcvMjAxNiAwODo0NTozMw", uri="/some/url", cnonce="YjRkMDQxYmM4MDFkYTMxOWZhNTViNGNmYTM5YzQyNGI=", nc=00000001, qop=auth, response="5d9643d083b2380f12d71855a98ceac3", opaque="0000000000000000", algorithm="MD5" 
Accept: */* 

< HTTP/1.1 200 OK 
< Cache-Control: private 
< Content-Length: 981 
< Content-Type: application/json; charset=utf-8 
< Server: Microsoft-IIS/7.5 
< X-AspNet-Version: 4.0.30319 
< X-Powered-By: ASP.NET 
< Date: Mon, 11 Jul 2016 08:44:33 GMT 
< 
* Connection #0 to host demo.someapi.net left intact 

und evertything funktioniert genau so, wie wir es erwarten. Unter Windows erhalten wir jedoch:

rprompt> getURL('http://demo.someapi.net/some/url', userpwd="demo:demo", httpauth=1L, verbose=TRUE) 
* Trying 195.224.16.34... 
* Connected to demo.someapi.net (195.224.16.34) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: C:/Users/username/Documents/R/win-library/3.3/RCurl/etc/ca-bundle.crt 
CApath: none 
* SSL connection using TLSv1.0/ECDHE-RSA-AES256-SHA 
* Server certificate: 
* subject: OU=GT56411961; OU=See www.rapidssl.com/resources/cps (c)15; OU=Domain Control Validated - RapidSSL(R); CN=*.someapi.net 
* start date: 2015-01-26 09:31:11 GMT 
* expire date: 2018-03-28 16:30:51 GMT 
* subjectAltName: demo.someapi.net matched 
* issuer: C=US; O=GeoTrust Inc.; CN=RapidSSL SHA256 CA - G3 
* SSL certificate verify ok. 
> GET /some/url HTTP/1.1 
Host: demo.someapi.net 
Accept: */* 

< HTTP/1.1 401 Unauthorized 
< Cache-Control: no-cache 
< Content-Type: text/html 
< Server: Microsoft-IIS/7.5 
< WWW-Authenticate: Digest realm="company.product", nonce="MTEvMDcvMjAxNiAwODo1MjowOA", opaque="0000000000000000", stale=false, algorithm=MD5, qop="auth" 
< X-Powered-By: ASP.NET 
< Date: Mon, 11 Jul 2016 08:51:07 GMT 
< Content-Length: 1293 
< 
* Ignoring the response-body 
* Connection #0 to host demo.someapi.net left intact 
* Issue another request to this URL: 'https://demo.someapi.net/some/url' 
* Found bundle for host demo.someapi.net: 0xaa60b80 
* Re-using existing connection! (#0) with host demo.someapi.net 
* Connected to demo.someapi.net (195.224.16.34) port 443 (#0) 
* Server auth using Digest with user 'demo' 
> GET /some/url HTTP/1.1 
Authorization: Digest username="demo",realm="",nonce="MTEvMDcvMjAxNiAwODo1MjowOA",uri="/some/url",cnonce="553f542ddef0e3c265e50539297bad81",nc=00000001,algorithm=MD5,response="1ec58793bb1d8142f09af112b905fa36",qop="auth",opaque="0000000000000000" 
Host: demo.someapi.net 
Accept: */* 

< HTTP/1.1 401 Unauthorized 
< Cache-Control: no-cache 
< Content-Type: text/html 
< Server: Microsoft-IIS/7.5 
* Authentication problem. Ignoring this. 
< WWW-Authenticate: Digest realm="company.product", nonce="MTEvMDcvMjAxNiAwODo1MjowOA", opaque="0000000000000000", stale=false, algorithm=MD5, qop="auth" 
< X-Powered-By: ASP.NET 
< Date: Mon, 11 Jul 2016 08:51:07 GMT 
< Content-Length: 1293 
< 
* Connection #0 to host demo.someapi.net left intact 

, die nur eine 401 Landing Page HTML zurückgibt.

Das Problem scheint zu sein, dass das Feld realm leer ist, aber ich habe keine Ahnung, wie das zu beheben oder sogar wie es funktioniert.

Es soll beachtet werden, dass sowohl von .NET webclient und Anfragen Bibliothek Python behandelt Dinge in Ordnung, aber leider hat dies in R. getan wird

Ich bin glücklich, alle R-Pakete zu verwenden, die zu lösen sind erforderlich, um zu helfen Dies.

Danke.

Antwort

0

Für alle anderen, die mit einem ähnlichen Problem enden, können Sie umgehen, indem Sie HTR verwenden und Ihre eigenen Handles verwenden.

make.request <- function (url, user, pass) { 
    handle <- httr::handle(url) 
    response <- GET(url=NULL, authenticate(user, pass, type="digest"), handle=handle) 
    # error checking and stuff... 
} 

Ich bin mir nicht sicher, was das Problem mit RCurl ist, obwohl.