[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HTTPAPI post trouble



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>

Hi Sean,

If anyone wants to prove that the return.php script works, ther is a test
script at http://mail.bestdist.com/test/test.php that posts to return.php

Any idea what I'm doing wrong?  (I automatically assume I've done
something wrong!)

You're doing several things wrong :) But actually, you did a really good job of showing me what needs to be done by providing me with the URL of your server as well as a test page that works so I can see what's going on.


a) The Web page "test.php" posts to /test/return.php, whereas the
    sample RPG program you sent posts to /return.php.  Apparently
    there is no "/return.php" so you get a "404 Not Found" error.

b) In the HTML document, you have fields called remote, password and
    Submit. However, in the RPG program you have user, password and
    submit. I don't know if your PHP script is case-sensitive or not,
    but I wouldn't be so bold as to assume that 'submit' and 'Submit' are
    the same.  And, "remote" and "user" are definitely not the same :)

c) A web browser will always assume that data keyed into an HTML form
    is content-type "application/x-www-form-urlencoded"  However, since
    HTTPAPI is more commonly used for Web services, it defaults to
    content-type "text/xml".  That means that the PHP script thinks
    that you're sending XML, and doesn't know how to interpret it!

So I changed your code a little bit, and tried using the following code instead. This code worked for me, hopefully it'll work for you too :)

H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')

D/copy libhttp/qrpglesrc,httpapi_h

     D CRLF            C                   CONST(x'0D25')
     D rc              s             10I 0
     D msg             s             52A
     D data            s           1024A

     c                   eval      data = 'remote=test' +
     c                                    '&password=pass' +
     c                                    '&Submit=Submit'

c eval rc = http_url_post('http://mail.bestdist.' +
c 'com/test/return.php':
c %addr(data):
c %len(%trimr(data)):
c '/tmp/return.php':
c HTTP_TIMEOUT:
c HTTP_USERAGENT:
c 'application/x-www-form-urlencoded')
c if rc <> 1
c eval msg = http_error
c dsply msg
c return
c endif


c eval *inlr = *on

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------