scala - databinder dispatch not properly handling HTTP 302 and authentication -
i using dispatch 0.11.0, scala 2.10 , trying code work
val svc = url("https://my-server/img/cat.jpg").as(username, password) val respbody = http(svc ok as.response(_.getresponsebodyasstream)) respbody oncomplete { case success(stream) => { val fos = new java.io.fileoutputstream("myfile.jpg") iterator .continually (stream.read) .takewhile (-1 !=) .foreach (fos.write) fos.close() } case failure(exception) => { logger.log.error(exception.tostring) } }
when server returns 302, dispatch doesn't handle authenticaton , failure executed. odd thing if point url json endpoint returns 401, authentication works fine. don't know why server setup return 2 different statuses unauthorized access need figure out how deal this. insights appreciated.
thanks, bob
try as_!() instead of as(), uses preemptive auth.
source:
def as(user: string, password: string) = subject.setrealm(new realmbuilder() .setprincipal(user) .setpassword(password) .build()) def as_!(user: string, password: string) = subject.setrealm(new realmbuilder() .setprincipal(user) .setpassword(password) .setusepreemptiveauth(true) .setscheme(authscheme.basic) .build())
Comments
Post a Comment