我正在尝试使用RESTSHARP在HP-ALM上发布实体。 到目前为止,我成功通过身份验证并获得了一些GET响应。 但是,不知何故,对于我发送的每个POST请求,我得到了这个回复:
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 :(得分:1)
Content-Type
无法与AddHeader
一起正常使用。
解决方案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);