ASP.Net 프로젝트에서 작업 중입니다. HP QC ALM 12.5x의 결함에 첨부 파일을 업로드해야합니다.C# HP QC ALM REST API : 결함 첨부 파일 업로드
인증 부분이 이미 완료되어 성공적으로 작동합니다. 나는 아래의 코드
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HPALMUrl + "/rest/domains/" + HPALMDomain + "/projects/" + HPALMProject + "/attachments");
request.Method = "POST";
request.Accept = "application/json";
request.Headers.Add("Accept-Language", "en-US");
request.Headers.Add("Accept-Encoding", "gzip, deflate, sdch");
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)";
request.ContentType = "Content-Type: multipart/form-data; boundary=" + boundary;
request.AllowWriteStreamBuffering = false;
request.ContentLength = imageBytes.Length;
authRequest.KeepAlive = true;
request.CookieContainer = createSessionRequest.CookieContainer; //successfully authenticated cookie
string contentDisposition = "form-data; entity.type=\"{0}\"; entity.id=\"{1}\"; filename=\"{2}\"; Content-Type=\"{3}\"";
request.Headers.Add("Content-Disposition", string.Format(contentDisposition, "defect", "4", "Defect Attachment.png", "application/octet-stream")); //I am not clear with passing content disposition. Please let me know if this should be modified.
내가
string path = @"C:\TestAttachment.png";
byte[] imageBytes = System.IO.File.ReadAllBytes(path);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
using (MemoryStream memoryStream = new MemoryStream(imageBytes))
{
byte[] buffer = new byte[imageBytes.Length];
int bytesRead = 0;
while ((bytesRead = memoryStream.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
}
}
var response = (HttpWebResponse)request.GetResponse(); //Receiving Error here
string responseText = string.Empty;
if (response.StatusCode == HttpStatusCode.OK)
responseText = "Update completed";
else
responseText = "Error in update";
은 알려 주시기 바랍니다 아래처럼 이미지 파일을 업로드하려고에게 쓴 WebException was unhandled: The remote server returned an error: (415) Unsupported Media Type.
수신 첨부 파일에 결함을 업로드에
, 내가 뭘 잘못하고 있는지.또한 rest api에 언급 된 콘텐츠 처리를 전달하는 것이 확실하지 않습니다.
미리 감사드립니다.
'Content-Disposition'은 * response * 헤더입니다. * 서버 *가 응답으로 설정합니다. 전혀 요청하지 마십시오. –
오류 자체는 첨부 파일이 * files *이지만 'Content-type'은'multipart/form-data'입니다. 양식을 게시하지 않았습니다. 새 파일을 작성 중입니다. 아마도 일반적인 HTTP와 REST가 어떤 방식으로 작동하는지 확인해야 할 것입니다. –
@PanagiotisKanavos 그러나 [API 참조] (https://admhelp.microfocus.com/alm/en/latest/api_refs/REST/webframe.htm#attachments.htm)에서 내용 부분은 헤더 부분에 언급되어 있습니다. –