我需要帮助才能使此代码正常工作。我对 VBA 编程以及与 HTTP Post 和表单相关的任何内容都是全新的。我已尝试通过阅读此处的问题并遵循 API 帮助来尽一切努力使其正常工作,但似乎没有任何效果。
这是您可以找到 API 参考的网站: http ://service.ringcentral.com/faxoutapi/
这也是我到目前为止的代码:
Sub POST()
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim strURL As String
Dim PostData As String
strURL = "https://service.ringcentral.com/faxapi.asp"
Const Boundary As String = "---------------------------7d54b1fee05aa"
WinHttpReq.Open "POST", strURL, False
WinHttpReq.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
PostData = "--" & Boundary & vbCrLf
PostData = PostData & "Content-Disposition: form-data; name=""Username""" & vbCrLf
PostData = PostData & "username" & vbCrLf
PostData = PostData & "--" & Boundary & vbCrLf
PostData = PostData & "Content-Disposition: form-data; name=""Password""" & vbCrLf
PostData = PostData & "password" & vbCrLf
PostData = PostData & "--" & Boundary & vbCrLf
PostData = PostData & "Content-Disposition: form-data; name=""Recipient""" & vbCrLf
PostData = PostData & "faxnumber" & vbCrLf
PostData = PostData & "--" & Boundary & vbCrLf
PostData = PostData & "Content-Disposition: form-data; name=""Coverpagetext""" & vbCrLf
PostData = PostData & "This is a test fax from web" & vbCrLf
PostData = PostData & "--" & Boundary & vbCrLf
WinHttpReq.Send (PostData)
MsgBox WinHttpReq.ResponseText
End Sub
我不断收到 5 的响应值,这意味着一般错误。我很确定表格与正确的格式不匹配。我还希望能够上传 API 参考中所示的文件。
提前致谢