首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何使用rest客户端为红宝石张贴一个图像?

我如何使用rest客户端为红宝石张贴一个图像?
EN

Stack Overflow用户
提问于 2010-05-19 05:49:56
回答 1查看 3.9K关注 0票数 0

我正试图找到一种使用Postful的方法,我需要在请求的正文中发布一个图像。我正在尝试使用rest-client (但对其他方式开放):

当我发布时遇到的错误是HTTP代码422

基本上,我是无知的,需要指导。*\

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-19 16:26:02

试一试

代码语言:javascript
复制
# 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.headers
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2863164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档