我試圖將此轉換:如何將帶有輸出選項的curl命令轉換爲httparty?
curl -k -v -X GET -H "Accept: application/pdf" https://username:[email protected]/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}"
響應返回
「無法轉換甕:C2M:文檔:ID:361從純文本/應用/ 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
日誌
編輯(4)
那麼我發現了一個與Rest客戶解決方案,我做了我對這個寶石的適度貢獻。
https://github.com/bolom/click2mail-ruby-gem
感謝每一個身體
順便說一句,你已經包括在主體這裏您的用戶名/密碼('Authorization'頭)。 – Ashe
@Len與RestClient。我沒有這個問題。感謝您的幫助 – Bolo
做得好!很高興聽到你的工作。 – Ashe