我正试图找到一种使用Postful的方法,我需要在请求的正文中发布一个图像。我正在尝试使用rest-client (但对其他方式开放):
当我发布时遇到的错误是HTTP代码422
基本上,我是无知的,需要指导。*\
class PostfulsController < ApplicationController
require 'rest_client'
def submit
body = "<?xml version='1.0' encoding='UTF-8'?>
<mail>
<documents>
<document>
<template>
<source>gallery</source>
<name>Postcard: Image fit front</name>
</template>
<sections>
<section>
<name>Text</name>
<text>Hello, World!</text>
</section>
<section>
<name>Image</name>
<attachment>#{attachment_id}</attachment>
</section>
</sections>
</document>
</documents>
<addressees>
<addressee>
<name>John Doe</name>
<address>123 Main St</address>
<city>Anytown</city>
<state>AZ</state>
<postal-code>10000</postal-code>
</addressee>
</addressees>
</mail>"
result = RestClient.post 'http://www.postful.com/service/mail',
body, :content_type => 'text/plain'
end
end发布于 2010-05-19 16:26:02
试一试
# result will contain the response
result = RestClient.post('http://www.postful.com/service/mail',
request.body,
{:content_type => 'text/plain',
'Authorization: Basic' => 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
p result.body
p result.code
p result.headershttps://stackoverflow.com/questions/2863164
复制相似问题