I have written a method to post messages to an uri.
public string RestClientPost(string uri, string message = null)
{
var client = new RestClient(uri);
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "text/xml");
if (!string.IsNullOrEmpty(message))
request.AddParameter(message, ParameterType.RequestBody);
var result = "";
var response = client.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{
result = response.Content;
Console.WriteLine(result);
}
else
{
result = response.StatusCode.ToString();
}
return result;
}
and below code is used above method to post.
public void test123()
{
string uri = "myuri"; //private uri, cannot expose.
var file= System.IO.File.ReadAllText(Path.Combine(Settings.EnvValPath, "RestClientXML", "test.XML"));
var content = new RestClientServices().RestClientPost(uri, file);
}
however, it returns "Unsupported Media type".
my test.XML's content is
<customer>
<customerName>test</customerName >
<customerStatus>OK</customerStatus >
</customer>
And using Advanced Rest Client Plugin for Google Chrome, I'm able to post it and return with string that I wanted. Is there something wrong?? I set "content-type" to "text/xml" in Advanced Rest Client.
- The return message is id of the customer. e.g: 2132
