vba - HTTPS POST 请求 VBA

标签 vba http outlook

我想为我的 ServiceNow 实例 API 创建 POST 请求。但我不知道如何使用库 VBA-Web . 我想在 ServiceNow 的表中创建一行。 我的代码:

Sub ToRequestSN()

Dim Body As New Dictionary
Body.Add "u_any_string", "test"
Body.Add "u_any_numeral", 12

Dim Client As New WebClient
Dim Response As WebResponse
Set Response = Client.PostJson("https://instance.sn.ru/api/now/table/u_table_test", Body)

Debug.Print Response.Content

End Sub

但是我收到了这个消息-

{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}

如何使用 VBA-Web 登录?

最佳答案

我找到了解决方案。我确实发送了选定的邮件(发件人的电子邮件)并传递给 Service Now。

Sub RequestToSN()

Dim Client As New WebClient
Dim Response As WebResponse
Dim Auth As New HttpBasicAuthenticator
Dim Body As New Dictionary
Dim myOlSel As Outlook.Selection
Dim oMail As Outlook.MailItem
Dim myOlExp As Outlook.Explorer


MsgTxt = ""
 Set myOlExp = Application.ActiveExplorer
 Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
 If myOlSel.Item(x).Class = OlObjectClass.olMail Then

 Set oMail = myOlSel.Item(x)
 MsgTxt = MsgTxt & oMail.SenderName
 ''Date = Date & oMail.CreationTime
 End If
 Next x


Body.Add "u_any_string", MsgTxt
Body.Add "u_any_numeral", 123

Auth.Setup _
    Username:="user", _
    Password:="user"

Set Client.Authenticator = Auth

Set Response = Client.PostJson("https://service.sn.com/api/now/table/u_table_test", Body)

End Sub

关于vba - HTTPS POST 请求 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55097097/

相关文章:

javascript - 加载本地文件时出现 "Cross origin requests are only supported for HTTP."错误

java - 使用java生成excel并在excel中创建宏

ms-access - Access 获取共享文件夹 session 的子文件夹

MS-Access 避免从表单字段 Word 文档导入空字段

html - 使用 $routeProvider 是否节省网络带宽?

vba - 循环遍历 Excel 工作表中的所有命名范围

c# - 从 Fiddler 隐藏我的应用程序产生的 Http(s) 流量

html - Outlook 等电子邮件客户端中的嵌入式图像缩小

excel - 使用 VBA 将 CSV 导入 Excel 匹配列标题

vba - 如何根据Excel中的单元格值更改公式?