Sending/uploading xml file in POST method of RestAPI using Ruby
I have used HTTPClient for authentication of Rest API and then used file
upload method for uploading file
Code:
require 'HTTPClient'
clnt = HTTPClient.new(path)
clnt.set_auth(path, 'username', 'password')
File.open('E:\Project_Groundwork\RestAPI\RestAPI Docs\postHost.xml') do
|file|
body = [{ 'Content-Type' => 'application/xml; charset=UTF-8',
:content => '<hosts><host hostName="host100"
description="First of my servers" monitorStatus="UP"
appType="NAGIOS" deviceIdentification="172.28.112.13"
monitorServer="localhost" deviceDisplayName="Device-50"
><properties><property name="Latency" value="125"
/></properties></host></hosts>' },
{ 'Content-Type' => 'application/xml',
'Content-Transfer-Encoding' => 'binary',
:content => file }]
io = clnt.post(path, body)
Above code authenticates successfully but after that returns '415
Unsupported Media type' error message. This error is returned when xml has
incorrect format. Though when I am sending xml data using 'RestClient'
Firefox Addon, then everything works fine.It means that my xml is correct.
Can anyone tell what am I doing wrong here.
No comments:
Post a Comment