5 Replies Latest reply on Feb 1, 2009 8:19 AM by kevwil69

    LrHttp.post params not reaching server

    kevwil69 Level 1
      I'm starting to write an LR2 plugin that will post images to a website using standard form posts (no fancy REST API or web services). I'm trying to learn the posting process by posting to a local web app which helps me debug what's going on.

      My debugging web app claims there were no parameters passed. I used a packet analyzer to see if they were actually passed or not - it appears they are sent in a separate packet.

      >local LrHttp = import 'LrHttp'
      local logger = import 'LrLogger'( 'PluginManager' )
      local debug, info, warn, err = logger:quick( 'debug', 'info', 'warn', 'err' )
      .... in dialog ....
      f:row {
      spacing = f:control_spacing(),
      f:push_button {
      width = 100,
      title = 'test auth post',
      enabled = true,
      action = function()
      local body, headers = LrHttp.post('http://localhost:8080/admin/signin/', 'user=foo\npwd=bar')
      debug(headers)
      end,
      },
      }

      I also get no debug info from the logger, as far as I can tell.

      Any help would be appreciated.
        • 1. Re: LrHttp.post params not reaching server
          escouten Adobe Employee
          Kevin, can you tell me whether this is happening on a Mac or Windows machine?
          • 2. Re: LrHttp.post params not reaching server
            kevwil69 Level 1
            I'm using a Mac.

            As an update, I put a logging message before the LrHttp.post call and I did get that output, so the process is just quietly dying when it hits the LrHttp.post call.

            I get the impression from the SDK API docs that I need to use a LrFunctionContext.postAsyncTaskWithContext() method, but I'm getting lost trying to figure out how all these things combine to do something useful.

            Does anyone have any sample code showing proper use of LrHttp.post?
            • 3. Re: LrHttp.post params not reaching server
              escouten Adobe Employee
              Kevin, I think this is a problem with your test server. I just wrote a little test script to verify that the input was posted as expected.<br /><br />I have MAMP installed on my Mac (http://www.mamp.info/). In its CGI-BIN folder, I installed the following Perl script:<br /><br />#!/usr/bin/perl<br /><br />print "Content-type: text/plain; charset=iso-8859-1\n\n";<br /><br />my $path;<br />if( $^O =~ /darwin/i ) {<br />     $path = "/Users/scouten/Desktop/args.txt";<br />} else {<br />     $path = "S:\\es-home\\env.txt";<br />     $path = "C:\\es-home\\env.txt" if( !-d "S:\\es-home" );<br />}<br /><br />open OUT, ">", $path;<br /><br />my $i = 0;<br />foreach $arg( @ARGV ) {<br />     print OUT "ARG $i -> $arg\n";<br />     $i++;<br />}<br /><br />print OUT "\n";<br /><br />foreach $key ( keys( %ENV )  ) {<br />     print OUT "$key -> $ENV{$key}\n";<br />}<br /><br />while( my $line = <STDIN> ) {<br />     print OUT "IN -> $line\n";<br />}<br /><br />close OUT;<br /><br /># --- (end of Perl script)<br /><br />I then ran the following script in Lightroom:<br /><br />LrTasks.startAsyncTask( function()<br />     LrHttp.post('http://localhost:8888/cgi-bin/dump-args-and-env.pl', 'user=foo\npwd=bar') <br />end )<br /><br />And confirmed that the output was as expected:<br /><br />SCRIPT_NAME -> /cgi-bin/dump-args-and-env.pl<br />SERVER_NAME -> localhost<br />SERVER_ADMIN -> you@example.com<br />HTTP_ACCEPT_ENCODING -> gzip, deflate<br />HTTP_CONNECTION -> keep-alive<br />REQUEST_METHOD -> POST<br />CONTENT_LENGTH -> 16<br />HTTP_ACCEPT -> */*<br />SCRIPT_FILENAME -> /Applications/MAMP/cgi-bin/dump-args-and-env.pl<br />SERVER_SOFTWARE -> Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2<br />QUERY_STRING -> <br />REMOTE_PORT -> 64643<br />HTTP_USER_AGENT -> Lightroom124410 CFNetwork/422.11 Darwin/9.6.0 (i386) (MacPro3%2C1)<br />SERVER_PORT -> 8888<br />SERVER_SIGNATURE -> <address>Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 Server at localhost Port 8888</address><br /><br />HTTP_ACCEPT_LANGUAGE -> en-us<br />REMOTE_ADDR -> ::1<br />CONTENT_TYPE -> text/plain<br />SERVER_PROTOCOL -> HTTP/1.1<br />PATH -> /usr/bin:/bin:/usr/sbin:/sbin<br />REQUEST_URI -> /cgi-bin/dump-args-and-env.pl<br />GATEWAY_INTERFACE -> CGI/1.1<br />SERVER_ADDR -> ::1<br />DOCUMENT_ROOT -> /Applications/MAMP/htdocs<br />HTTP_HOST -> localhost:8888<br />IN -> user=foo<br /><br />IN -> pwd=bar
              • 4. Re: LrHttp.post params not reaching server
                kevwil69 Level 1
                Ok, I'll have a look at my test server code. I know the test server is getting called and a response is being made. I don't know if it's doing everything correctly, but my LrHttp code isn't handling the data coming back.

                Thanks for the example usage with LrTasks.startAsyncTask, I'll give that a shot as well.

                Thanks for the help!
                • 5. Re: LrHttp.post params not reaching server
                  kevwil69 Level 1
                  Well, I triple-checked my server code and made sure I'm getting data back on posts, so I'm positive my test server isn't the problem.

                  I can see that my post is hitting the server, but nothing comes back. What I'm trying to accomplish is using a login form and parsing out the session cookie, so that I can successfully post an image as an authenticated user.

                  Here's my current code. I'm getting the debug output in the Console, the server receives the post, then ... nothing.

                  
                  
                  f:row {
                  spacing = f:control_spacing(),
                  f:push_button {
                    width = 100,
                    title = 'test auth post',
                    enabled = true,
                    action = function()
                     debug('about to post to server')
                     local success, body, headers = LrFunctionContext.pcallWithContext(
                      "post task",
                      function()
                       return LrHttp.post("http://localhost:8080/admin/signin/", "user=foo\npwd=bar")
                      end
                     )
                     if not success then
                      error("an error occurred" .. headers.error)
                     end
                     assert(body, "no body returned")
                     assert(headers, "no headers returned")
                     info(toString(headers))
                     info(toString(body))
                    end,
                  },
                  }