0

I am trying to post an entity on HP-ALM, by using RESTSHARP. So far, I successfully authenticated and got some GET responses fine. But, somehow, for each POST request I send, I get this response:

qccore.general-error Unsupported Media Type

This is one of the many trials I made (for posting a defect). Any ideas for what is wrong here?

    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;
    }

Thank you.

mor mazar
  • 1
  • 1
  • 1

1 Answers1

1

Content-Type doesn't work correctly with AddHeader.

Solution here.

The intended way to accomplish this is to use AddBody() along with RestRequest.RequestFormat. An example:

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);
Community
  • 1
  • 1
Ross Presser
  • 6,027
  • 1
  • 34
  • 66