【发布时间】:2016-10-25 00:49:08
【问题描述】:
我收到一个我无法弄清楚的错误代码!在我的 vba 中,我正在创建一个 excel 文件并使用 POST 将其上传到服务器。我可以手动导入此文件没有问题,但由于某种原因,我的代码从服务器收到失败响应 - 代码 415,损坏的表单数据:过早结束。
Sub offline_punch()
Dim newwkb As Workbook
Dim thiswkb As Workbook
Dim URLReportop As String
Dim myrequestop As Object
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Set thiswkb = ActiveWorkbook
Set StartCell = thiswkb.Worksheets("offline_punch").Range("A1")
Set newwkb = Workbooks.Add
'Find LastRow and LastColumn
LastRow = thiswkb.Worksheets("offline_punch").Cells(thiswkb.Worksheets("offline_punch").Rows.Count, StartCell.Column).End(xlUp).Row
LastColumn = thiswkb.Worksheets("offline_punch").Cells(StartCell.Row, thiswkb.Worksheets("offline_punch").Columns.Count).End(xlToLeft).Column
thiswkb.Worksheets("offline_punch").Range(StartCell, thiswkb.Worksheets("offline_punch").Cells(LastRow, LastColumn)).Copy
newwkb.Worksheets("sheet1").Range("A1").PasteSpecial xlPasteValues
newwkb.SaveAs ("E:\Documents\PunchImport" & Format(Now(), "yyyymmddhhmmss") & ".xls"), 56
thiswkb.Activate
Call getToken
'Send raw punch import to wfr
Set myrequestop = CreateObject("winhttp.winhttprequest.5.1")
URLReportop = ("https://secure.saashr.com:443/ta/rest/v1/import/119")
myrequestop.Open "POST", URLReportop, False
myrequestop.setRequestHeader "Authentication", "Bearer " & Token
myrequestop.setRequestHeader "Content-Type", "multipart/form-data; boundary=abcdefghi-jklmnop; charset=UTF-8"
myrequestop.setRequestHeader "Content-length", 1000
myrequestop.Send newwkb
MsgBox (myrequestop.responseText & " " & Now)
newwkb.Close
Set newwkb = Nothing
thiswkb.Activate
End Sub
【问题讨论】:
标签: excel http-post multipartform-data boundary vba