如何在VBA中传递身份验证凭据 [英] How to pass authentication credentials in VBA

查看:256
本文介绍了如何在VBA中传递身份验证凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个VBA宏,该宏将通过我的邮件地址并获取一些内容(JIRA的REST API),但是将我的代码从java转换为VBA有一些困难。目前,这是我的java代码:

I'm trying to write a VBA macro that would pass my credentails to an address and fetch some content (REST API for JIRA), but I'm having some difficulties converting my code from java to VBA. Currently, this is my java code:

        String username = "myUser";
        String password = "myPassword";

        String authString = username + ":" + password;
        byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
        String authStringEnc = new String(authEncBytes);
        System.out.println("Base64 encoded auth string: " + authStringEnc);

        URL url = new URL(address);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setRequestProperty("Authorization", "Basic "
                + authStringEnc);
        InputStream is = urlConnection.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);

我正在尝试将其转换为VBA,我不完全确定如何处理它,或者如果有一些图书馆会促进这一点。

And I'm trying to convert this to VBA, I'm not entirely sure how to handle it, or if there's some library that would facilitate this.

推荐答案

对于基本身份验证,您可以简单地:

For Basic Authentication you can simply:

Dim response As String

With CreateObject("Microsoft.XMLHTTP")
  .Open "GET", address, false, username, password
  .Send
  response = .responseText
End With

Msgbox response

这篇关于如何在VBA中传递身份验证凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆