2016-07-14 7 views
1

HP Quality Center를 사용하며 11.5x를 12.21로 업그레이드하고 API를 사용하여 티켓을 만듭니다. 접속 및 티켓 생성은 정상이지만 파일 첨부는 아닙니다.QC REST API : 지원되지 않는 미디어 유형

나는 내가 {"Id":"qccore.general-error","Title":"Illegal multi-part arguments. Attachment wasn't created.","ExceptionProperties":null,"StackTrace":null}

그래서 나는 다중 구조의 실수 나 나쁜 헤더가있어 다른 다중/폼 데이터를 사용하는 경우 다음

{"Id":"qccore.general-error","Title":"Unsupported Media Type","ExceptionProperties":null,"StackTrace":null} 내 코드

$filename = $file->name; 
$eol = "\r\n"; 
$mime_boundary = 'boundary'; 

$content = '--' . $mime_boundary . $eol; 
$content .= 'Content-Disposition: form-data; name="entity.type"'; 
$content .= $eol . $eol; 
$content .= 'defect'; 
$content .= $eol; 

$content = '--' . $mime_boundary . $eol; 
$content .= 'Content-Disposition: form-data; name="entity.id"'; 
$content .= $eol . $eol; 
$content .= $id; 
$content .= $eol; 

$content = '--' . $mime_boundary . $eol; 
$content .= 'Content-Disposition: form-data; name="filename"'; 
$content .= $eol . $eol; 
$content .= utf8_encode($filename); 
$content .= $eol; 

$content .= '--' . $mime_boundary . $eol; 
$content .= 'Content-Disposition: form-data; name="file"; filename="' . utf8_encode($filename) . '"'; 
$content .= $eol; 
$content .= 'Content-Type: ' . $file['type']; 
$content .= $eol . $eol; 

$dt = explode('-', $file->create_dt); 
$path_file = $config['files']['forms_attachments_path'] . DIRECTORY_SEPARATOR . $dt[0] . DIRECTORY_SEPARATOR . $dt[1] . DIRECTORY_SEPARATOR . $file->filename; 
$handle = fopen($path_file, 'r'); 
$content .= fread($handle,filesize($path_file)); 
fclose($handle); 

$content .= $eol; 
$content .= '--' . $mime_boundary . '--'; 

$header = array(
    'Content-Type: multipart/mixed; boundary='.$mime_boundary, 
    'Content-Length: '.strlen($content), 
    'Accept: application/json' 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 
curl_setopt($ch, CURLOPT_COOKIE, $cookiess); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_PROXY, null); 
curl_setopt($ch, CURLOPT_URL, $config['qc']['url'] . '/api/domains/' . $config['qc']['domain']. '/projects/' . $config['qc']['project'] . '/attachments/'); 

$output = curl_exec($ch); 
curl_close($ch); 
var_dump($output); 

입니다 있어요 content-type에 대해서는,하지만 우리가 테스트 한 모든 것은 실패합니다.

첨부 파일을 옥텟 스트림 방식으로 넣으려고했지만 미디어 유형 오류가 발생했습니다.

귀하의 도움에 감사드립니다.

답변

0

약간 다른 종점을 사용합니다. 많은 "오래된"엔드 포인트가 HP ALM 12.x에서 여전히 작동하지만 일부는 동작을 많이 변경했으며 대부분은 대신 사용해야하는 대체품이 있다는 것을 알았습니다.

우리는 /rest/domains/DOMAIN/projects/PROJECT/defects/4711/attachments (/api/... 대신에 양식 필드를 통해 엔티티 ID 전달)을 사용합니다.

그런 다음, 우리는 HTTP 헤더를 추가 Slug: myfilename.txt

우리의 다른 HTTP 헤더는 다음과 같습니다

Accept: application/xml 
Content-Type: application/octet-stream 

이제, 우리는 해당 엔드 포인트에 파일 데이터를 게시 할 수 있습니다. HP ALM 12.50에서 제대로 작동합니다.

유사한 예 (Java 코드, 미안)에 대해서는 http://stevenckwong.com/wp/2016/05/09/how-to-upload-an-attachment-to-a-test-in-alm-via-the-rest-api/도 참조하십시오.