0

我正在尝试将其转换为:

curl -k -v -X GET -H "Accept: application/pdf" https://username:password@rest.click2mail.com/v1/mailingBuilders/456/proofs/1 -o myProof

为 httparty。这是我的代码:

@auth = {:username => 'test', :password => 'test'}
options = {:headers => {'Accept' => 'application/pdf'}, :basic_auth => @auth }
body = HTTMultiParty.get("https://stage.rest.click2mail.com/v1/mailingBuilders/54544/proofs/1", options)

File.open("myProof", "w") do |file|
  file.write body
end

p "Reponse #{body.parsed_response}"

响应返回

“无法将 urn:c2m:document:id:361 从 text/plain 转换为 application/pdf”

编辑 (2)

body.inspect 带有“text/plain”返回

#<HTTParty::Response:0x8 @parsed_response=nil, @response=#<Net::HTTPNotAcceptable 406 Not Acceptable readbody=true>, @headers={\"date\"=>[\"Sun, 06 May 2012 11:22:12 GMT\"], \"server\"=>[\"Jetty(6.1.x)\"], \"content-length\"=>[\"0\"], \"connection\"=>[\"close\"], \"content-type\"=>[\"text/plain; charset=UTF-8\"]}>

带有“应用程序/pdf”

#<HTTParty::Response:0x7fce08a92260 @parsed_response=\"Cannot convert urn:c2m:document:id:361 from text/plain to application/pdf\", @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={\"date\"=>[\"Sun, 06 May 2012 11:24:09 GMT\"], \"server\"=>[\"Jetty(6.1.x)\"], \"content-type\"=>[\"application/pdf\"], \"connection\"=>[\"close\"], \"transfer-encoding\"=>[\"chunked\"]}>

编辑 3

API:第 8 步

https://developers.click2mail.com/rest-api#send-a-test-mailing

编辑 4

带有 debug_ouput 选项

带有“应用程序/pdf”

opening connection to stage.rest.click2mail.com...
opened
<- "GET /v1/mailingBuilders/54544/proofs/1 HTTP/1.1\r\nAccept: application/pdf\r\nAuthorization: Basic Ym9sb2RldjptVW43Mjk0eQ==\r\nConnection: close\r\nHost: stage.rest.click2mail.com\r\n\r\n"
-> "HTTP/1.1 400 Bad Request\r\n"
-> "Date: Sun, 06 May 2012 14:05:30 GMT\r\n"
-> "Server: Jetty(6.1.x)\r\n"
-> "Content-Type: application/pdf\r\n"
-> "Connection: close\r\n"
-> "Transfer-Encoding: chunked\r\n"
-> "\r\n"
-> "49\r\n"
reading 73 bytes...
-> ""
-> "Cannot convert urn:c2m:document:id:361 from text/plain to application/pdf"
read 73 bytes
reading 2 bytes...
-> ""
-> "\r\n"
read 2 bytes
-> "0\r\n"
-> "\r\n"
Conn close

带有“文本/纯文本”

opening connection to stage.rest.click2mail.com...
opened
<- "GET /v1/mailingBuilders/54544/proofs/1 HTTP/1.1\r\nAccept: text/plain\r\nAuthorization: Basic Ym9sb2RldjptVW43Mjk0eQ==\r\nConnection: close\r\nHost: stage.rest.click2mail.com\r\n\r\n"
-> "HTTP/1.1 406 Not Acceptable\r\n"
-> "Date: Sun, 06 May 2012 14:14:19 GMT\r\n"
-> "Server: Jetty(6.1.x)\r\n"
-> "Content-Length: 0\r\n"
-> "Connection: close\r\n"
-> "Content-Type: text/plain; charset=UTF-8\r\n"
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close

从 curl 命令记录

编辑 (4)

好吧,我找到了 Rest Client 的解决方案,我用这个 gem 做了我的微薄贡献。

https://github.com/bolom/click2mail-ruby-gem

谢谢大家

4

3 回答 3

1

您也可以使用 net::http (需要 'net/http') 有关如何下载大文件的示例,请参阅此问题。

于 2012-05-06T10:31:13.420 回答
0

尝试这个:

body = Httparty.get("https://username:password@rest.click2mail.com/v1/mailingBuilders/456/proofs/1")

File.open("myProof", "w") do |file|
    file.write body
end
于 2012-05-06T10:20:22.427 回答
0

问题在于它本身的 API。

它与您如何调用 API 以获取证明或您使用的 Rest API 库无关。问题是您用来创建此 mailingBuilders 的任何内容都会导致出现错误消息“无法将 urn:c2m:document:id:361 从 text/plain 转换为 application/pdf”的问题。

请向 support@click2mail.com 发送您为创建此 mailingBuilder 所做的确切操作,以便我们查看它并查看问题所在。

于 2012-05-07T14:51:31.890 回答