2014-08-31 96 views
0

我試圖通過使用RESTSHARP在HP-ALM上發佈實體。 到目前爲止,我已成功驗證並獲得了一些GET響應。 但是,不知何故,每個POST請求我送,我得到這樣的響應:通過RestSharp POST到ALM:不支持的介質類型

qccore.general錯誤 不支持的媒體類型

這是許多試驗我做了(張貼缺陷)之一。任何想法在這裏是錯誤的?

private RestRequest createPOSTRequest() 
    { 
     RestRequest Request = m_client.CreateRequest(m_client.BaseUrl + 
     "rest/domains/{domain}/projects/{project}/{entity-type}", Method.POST); 
     Request.AddUrlSegment("domain", m_client.domain); 
     Request.AddUrlSegment("project", m_client.project); 
     Request.AddUrlSegment("entity-type", "defects"); 

     Request.AddHeader("Content-Type", "application/xml"); 
     Request.AddHeader("Accept", "application/xml"); 

     Request.RequestFormat = DataFormat.Xml; 

     m_xmlBody = = @"<?xml version='1.0' encoding='UTF-8'? encoding='UTF-8' standalone='yes'?>"+ 
           "<Entity Type='defect'>"+ 
           "<Fields>" + 
           "<Field Name='detected-by'>"+ 
           "<Value>sa</Value>"+ 
           "</Field>"+ 
           "<Field Name='creation-time'>"+ 
           "<Value>2010-03-02</Value>"+ 
           "</Field>"+ 
           "<Field Name='severity'>"+ 
           "<Value>2-Medium</Value>"+ 
           "</Field>"+ 
           "<Field Name='name'>"+ 
           "<Value>Defect Entity.</Value>"+ 
           "</Field>"+ 
           "</Fields>"+ 
           "</Entity>"; 

     return Request; 
    } 

謝謝。

回答

0

Content-TypeAddHeader無法正常工作。

解決方案here

完成此操作的預期方法是將AddBody()與RestRequest.RequestFormat一起使用。舉例:

var client = new RestClient(); 
// client.XmlSerializer = new XmlSerializer(); // default 
// client.XmlSerializer = new SuperXmlSerializer(); // can override with any implementaiton of ISerializer 

var request = new RestRequest(); 
request.RequestFormat = DataFormat.Xml; 
request.AddBody(objectToSerialize); 
相關問題