Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails http POST错误_Ruby On Rails_Xml_Http Post - Fatal编程技术网

Ruby on rails http POST错误

Ruby on rails http POST错误,ruby-on-rails,xml,http-post,Ruby On Rails,Xml,Http Post,我正试图通过Restclient的http POST请求将xml发送到另一个Web服务器。代码如下: response = RestClient.post 'https://secure.rowebooks.co.uk/testorders/orders.aspx', :content_type => "text/xml", :myfile => File.read("#{Rails.root}/public/shared/#{@book}.xml") 但我得到了这个错误 ERR

我正试图通过Restclient的http POST请求将xml发送到另一个Web服务器。代码如下:

response =  RestClient.post 'https://secure.rowebooks.co.uk/testorders/orders.aspx', :content_type => "text/xml", :myfile => File.read("#{Rails.root}/public/shared/#{@book}.xml")
但我得到了这个错误

ERROR 2 Data at the root level is invalid. Line 1, position 1.ERROR3 Object reference not set to an instance of an object.
我被告知我收到了这个错误,因为XML文件不在调用的内容中。它必须在内容中。我不知道这是什么意思

如有任何建议/线索,将不胜感激


谢谢

你应该这样做:

response =  RestClient.post( 'https://secure.rowebooks.co.uk/testorders/orders.aspx', 
File.read("#{Rails.root}/public/shared/#{@book}.xml"), 'Content-Type' => 'text/xml' )

您好,谢谢您的回复,但您发布的代码返回错误-“语法错误,意外'\n',预期为tASSOC”。少了什么吗?非常感谢毛里西奥。我非常感谢你的帮助。