任何人都知道如何通过RESTful在HP ALM中上传附件?目前我正在以这种形式写我的请求标题/正文:
Dim request As WebRequest = WebRequest.Create("https://[server].saas.hp.com/qcbin/rest/domains/[DOMAIN_NAME]/projects/[PROJECT_NAME]/runs/[ID_EXECUTION]/attachments/")
request4.Method = "Post"
Dim fileToSend As Byte() = File.ReadAllBytes("C:\Users\ECELESTE\Desktop\Teste.txt")
Dim preAttachment As String = "Content-Disposition" + ": " + "form-data; filename=""Test.txt"""
request.ContentType = "multipart/form-data; boundary=boundary"
Using requestStream As Stream = request.GetRequestStream()
Dim preAttachmentBytes As Byte() = UnicodeEncoding.UTF8.GetBytes(preAttachment)
requestStream.Write(preAttachmentBytes, 0, preAttachmentBytes.Length)
requestStream.Write(fileToSend, 0, fileToSend.Length)
End Using
Dim webResponse As WebResponse = request.GetResponse()
但是此代码返回错误(500 - 内部服务器错误)。
其他信息:HP ALM 12.01版/代码语言VB.NET
谢谢!
答案 0 :(得分:1)
似乎缺少必填表格字段,"文件名"。
另请使用" boundary"的值在" ContentType"中指定分割每个表单字段。
最重要的是," requestStream"在您的代码中应写下以下内容:
--boundary
Content-Disposition: form-data; name="filename"
Test.txt
--boundary
Content-Disposition: form-data; name="file"; filename="Test.txt"
Content-Type: text/plain
[Content of file, your "fileToSend"]
--boundary--
"文件名"中的文件名section必须与" file"中的文件名相同部分。
希望它对你有所帮助。