tyazid / RTSP-Java-UrlConnection

Full java Implemetation of RTSP (RFC 2326) command protocol.
Apache License 2.0
33 stars 13 forks source link

RTSP/1.0 401 Unauthorized #2

Open willagner opened 7 years ago

willagner commented 7 years ago

I have this program:

     httpCam   = "rtsp://admin:admin@IP:PORT/cam/realmonitor?channel=1&subtype=0"";  

    if("rtsp".equals(httpCam.substring(0,4))){
        java.net.URL.setURLStreamHandlerFactory( new RtspURLStreamHandlerFactory());
        java.net.URL url = new URL(httpCam);

        RtspURLConnection urlc = (RtspURLConnection) url.openConnection();

        if("rtsp".equals(url.getProtocol())){
            try{
                urlc.connect();
            }catch(Exception ex){
                geraLog();
                logger.log(Level.INFO,"Timeout na conexão do link: " + httpCam);
                logger.log(Level.INFO,"Verifique o link digitado ou se está sendo possível conectar-se a ele");
                logger.log(Level.INFO, ex.getMessage());
                System.exit(0);
            }   
        }
    }

But he return this error: RTSP/1.0 401 Unauthorized


This is the log application: RtspURLConnection.computeHostAndPort() /////// PORT = 554 false ######## SEND TO 192.168.25.200:554 OPTIONS RTSP/1.0 CSeq: 1

########

Client.sendRequest() IS CONNECTION ALIVE = true Client.sendRequest() REQ =

OPTIONS * RTSP/1.0 CSeq: 1

[CONNECTION.DUMPING] .... RECEIVEING: TSP/1.0 401 Unauthorized CSeq: 1 WWW-Authenticate: Digest realm="Login to 9JIE4900821BD", nonce="70b360d7ed176aed f820b90dab8595d8"

[CONNECTION.DUMPING] .... DONE: Client.sendRequest() T-OUT =false Server.parse() RTSP/1.0 401 Unauthorized CSeq: 1 WWW-Authenticate: Digest realm="Login to 9JIE4900821BD", nonce="70b360d7ed176aed f820b90dab8595d8"

RTSP/1.0 401 Unauthorized CSeq: 1 WWW-Authenticate: Digest realm="Login to 9JIE4900821BD", nonce="70b360d7ed176aed f820b90dab8595d8"

How i can solve this?

tyazid commented 7 years ago

Hi, this RTSP framework default imp doesn't support " Digest access authentication" that your camera server need in order to allow you communication establishment. but anyway, RtspURLConnection is an URLConnection and so "Authorization:" could be add the request header. I'll try to have a look on the framework (If I can remember everything :) ) asap and send you a "how to " example. Regards.

willagner commented 7 years ago

Thanks for your attention.

I try use this: String userPassword = username + ":" + password; Encoder encoder = Base64.getEncoder(); String encodeToString = encoder.encodeToString(userPassword.getBytes()); urlc.setRequestProperty("Authorization", "Digest " + encodeToString);

But it did not work