Greetings, and Happy Holidays! I'm having a problem utilizing an API and its required fields with HTTP::Request::Common. The first request returns a token (this works), that is used by the second request to upload an image (my problem). I've tried numerous permutations but can't seem to nail it. There is no formal documentation for the api, so I've just been poking it with a pointy stick. The api requires the following: from a coworkers ruby program:

http = HTTPClient.new jpeg_path = "#{Rails.root}/#{[path]}" uri = URI.parse(url) File.open(jpeg_path) do |jpeg| headers = {"Authorization" => "Bearer #{auth_info['access_token']}" +} body = { 'original' => jpeg, 'slug' => 'woohoo' } response = http.post(uri, body, headers)

This is what I have so far and the response

my $browser = LWP::UserAgent->new; $browser->timeout(30); my $response = $browser->request( POST $upload_url, Content_Type => 'form-data', Headers => { Authorization => 'Bearer ' . $json_auth->{access_ +token} }, Content => [ 'slug' => 'woohoo', Filedata => [$image], ] );
HTTP/1.1 400 Bad Request Cache-Control: no-store, no-transform Date: Thu, 28 Nov 2013 14:28:57 GMT Server: Jetty(7.4.5.v20110725) WWW-Authenticate: Bearer Content-Type: application/json Client-Date: Thu, 28 Nov 2013 14:28:57 GMT Client-Peer: xxx.xxx.xxx.xxx:xxx Client-Response-Num: 1 Client-SSL-Cert-Issuer: /C=US/O=GeoTrust, Inc./CN=RapidSSL CA Client-SSL-Cert-Subject: /serialNumber=mUOvwBDD0H95debkB/h5KKaWmke7/2c +y/OU=GT28122842/OU=See www.rapidssl.com/resources/cps (c)12/OU=Domain + Control Validated - RapidSSL(R)/CN=*.private.dev.xxxxx.com Client-SSL-Cipher: RC4-MD5 Client-SSL-Warning: Peer certificate not verified Client-Transfer-Encoding: chunked Set-Cookie: NSC_dnt-tfswjdf-iuuq=ffffffffc3a0d98c45525d5f4f58455e445a4 +a4229a0;expires=Thu, 28-Nov-2013 14:31:03 GMT;path=/;secure;httponly X-NYTD-CMS-Host: cms-service01.qprvt.xxxxxx.com { "error": "invalid_request", "error_description": "This service requires authentication" }

Any help would be greatly appreciated! Thanks in advance,

2013-11-28 Retitled by GrandFather, as per Monastery guidelines


In reply to Request to Upload an Image by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.