Cisco Cisco Configuration Engine 3.5.3 Guida Dello Sviluppatore

Pagina di 348
3-10
Cisco Configuration Engine Software Development Kit API Reference and Programmer Guide 3.5.3
OL-17661-04
Chapter 3      Configuration Service
Template File Manager
        NVPair[] opts = { new NVPair("","") };
        NVPair[] file = { new NVPair(paramName, uploadFileName) };
        NVPair[] hdrs = new NVPair[1];
        byte[] data = Codecs.mpFormDataEncode(opts, file, hdrs);
        HTTPConnection con = new HTTPConnection( url );
        HTTPResponse rsp = con.Post( path, data, hdrs );
        if ( rsp.getStatusCode() >= 300 )
        {
            System.err.println( "Error: " + rsp.getReasonLine() );
            String errorMsg =  new String(rsp.getData());
            System.err.println( errorMsg );
            _sBuff.append(errorMsg);
        }
        else
        {
            BufferedReader _hIn = new BufferedReader(new InputStreamReader
                                                    (rsp.getInputStream()));
            String _sLine = null;
            while((_sLine = _hIn.readLine()) != null)
            {
                _sBuff.append(_sLine);
            }
            _hIn.close();
        }
        return _sBuff.toString();
    }
}
Note
The method Codecs.mpFormDataEncode(opts, file, hdrs) encodes the form data for 
multipart/form-data content type.