Java Waffle-绝对初学者

时间:2018-07-27 14:34:46

标签: java kerberos waffle

我们有一个使用Kerberos身份验证的站点。我以前从未使用过Java和Eclipse,因此我的知识非常有限。

我希望实现的功能类似于我使用python所做的事情:

def DownloadFileFromSite(url):
    FileName = ''
    if 'download' not in url:
        print ('ERROR: Change the following url to the proper download link.\n' + url)
    else:   
        try:
            # Disable SSL warnings
            requests.packages.urllib3.disable_warnings()
            kerberos_auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
            response = requests.get(url, auth=kerberos_auth)
            response.raise_for_status()  # Check for exceptions
        except:
            print ('ERROR: HTTP Connection error. Check the network connection, and the inside links in CQ.')
        # If the response has Content-Disposition, we take file name from it
        if 'content-disposition' in response.headers:
            FileName = re.findall("filename=(.+)", response.headers['content-disposition'])
            if FileName:
                FileName = FileName[0]
        # if we were redirected, we take the real file name from the final URL
        else:
            FileName = re.search(r'/([^/;]+)(;.*)?$', response.url)
            if FileName:
                FileName = FileName.group(1)
        # Save the downloaded file to C:\temp
        if FileName:
            try:
                with open(strWorkspace + '\\' + FileName, 'wb') as DownloadedFile:
                    DownloadedFile.write(response.content)
            except:
                print ('\nError occured while saving downloaded contents from site.\n')
        else:
            print ('ERROR:  ' + url)

我想用Java实现,但是我不知道如何开始。我已经看过示例,但是我是Java的新手,我不知道如何处理它们。

0 个答案:

没有答案
相关问题