我正在尝试将其转换为:
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
谢谢大家