Loading ...
Sorry, an error occurred while loading the content.

Post params don't show up on server side

Expand Messages
  • jameschao122
    Hi, I currently switched over from prototype to YUI and have some problems using the connection manager. I m using the POST method with some parameters, but
    Message 1 of 8 , May 30, 2007
    • 0 Attachment
      Hi,

      I currently switched over from prototype to YUI and have some problems
      using the connection manager.

      I'm using the POST method with some parameters, but when my async
      connection is sent, the server side only receives some parameters in
      the URL, but not the ones that I pass into the 4th argument of
      asyncRequest. (I'm using Apache ASP on the server).

      Another related thing I noticed is that the Params tab don't show up
      for these requests either, and the "Post" tab shows the parameters as
      a single long string, rather than a key-value column like it did when
      I was using prototype.js. This was the way when I was looking at the
      official YUI Post method example as well.

      Any ideas what I'm doing wrong?

      James
    • jameschao122
      OK, seems like the problem is with the Content-Type header. By default, it is application/x-www-form-urlencoded; charset=UTF-8 . When I change it to
      Message 2 of 8 , May 30, 2007
      • 0 Attachment
        OK, seems like the problem is with the "Content-Type" header.

        By default, it is "application/x-www-form-urlencoded; charset=UTF-8".

        When I change it to "application/x-www-form-urlencoded", it works.

        Does anybody know if this is the right way to do it or why the default value doesn't work??

        BTW, this is the code I'm doing to change the header:

        YAHOO.util.Connect.setDefaultPostHeader(false);
        YAHOO.util.Connect.initHeader('Content-Type', 'application/x-www-form-urlencoded');



        --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
        >
        > Hi,
        >
        > I currently switched over from prototype to YUI and have some problems
        > using the connection manager.
        >
        > I'm using the POST method with some parameters, but when my async
        > connection is sent, the server side only receives some parameters in
        > the URL, but not the ones that I pass into the 4th argument of
        > asyncRequest. (I'm using Apache ASP on the server).
        >
        > Another related thing I noticed is that the Params tab don't show up
        > for these requests either, and the "Post" tab shows the parameters as
        > a single long string, rather than a key-value column like it did when
        > I was using prototype.js. This was the way when I was looking at the
        > official YUI Post method example as well.
        >
        > Any ideas what I'm doing wrong?
        >
        > James
        >
      • tssha
        ... Interesting. Can you show the actual POST message you re sending as the fourth argument? Regards, Thomas
        Message 3 of 8 , May 30, 2007
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
          >
          > OK, seems like the problem is with the "Content-Type" header.
          >
          > By default, it is "application/x-www-form-urlencoded; charset=UTF-8".
          >
          > When I change it to "application/x-www-form-urlencoded", it works.
          >
          > Does anybody know if this is the right way to do it or why the default
          > value doesn't work??
          >
          > BTW, this is the code I'm doing to change the header:
          >
          > YAHOO.util.Connect.setDefaultPostHeader(false);
          > YAHOO.util.Connect.initHeader('Content-Type',
          > 'application/x-www-form-urlencoded');

          Interesting. Can you show the actual POST message you're sending as
          the fourth argument?

          Regards,
          Thomas
        • jameschao122
          My post parameters look something like this: id=1180625935031062&action=get_user_prefs&data=%7B%7D All of my posts have a parameter for ID, action, and data
          Message 4 of 8 , May 31, 2007
          • 0 Attachment
            My post parameters look something like this:

            "id=1180625935031062&action=get_user_prefs&data=%7B%7D"

            All of my posts have a parameter for ID, action, and data (sometimes null). And this is exactly what I'm passing in as the fourth parameters.

            --- In ydn-javascript@yahoogroups.com, "tssha" <tsha@...> wrote:
            >
            > --- In ydn-javascript@yahoogroups.com, "jameschao122" jchao@ wrote:
            > >
            > > OK, seems like the problem is with the "Content-Type" header.
            > >
            > > By default, it is "application/x-www-form-urlencoded; charset=UTF-8".
            > >
            > > When I change it to "application/x-www-form-urlencoded", it works.
            > >
            > > Does anybody know if this is the right way to do it or why the default
            > > value doesn't work??
            > >
            > > BTW, this is the code I'm doing to change the header:
            > >
            > > YAHOO.util.Connect.setDefaultPostHeader(false);
            > > YAHOO.util.Connect.initHeader('Content-Type',
            > > 'application/x-www-form-urlencoded');
            >
            > Interesting. Can you show the actual POST message you're sending as
            > the fourth argument?
            >
            > Regards,
            > Thomas
            >
          • jameschao122
            Also, I actually have to do the following to get the connection manager to send the request with the correct header: YAHOO.util.Connect.resetDefaultHeaders();
            Message 5 of 8 , May 31, 2007
            • 0 Attachment
              Also, I actually have to do the following to get the connection manager to send the request with the correct header:

                   YAHOO.util.Connect.resetDefaultHeaders();
                   YAHOO.util.Connect.setDefaultPostHeader(false);
                   YAHOO.util.Connect.initHeader('Content-Type', 'application/x-www-form-urlencoded', true);


              --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
              >
              > My post parameters look something like this:
              >
              > "id=1180625935031062&action=get_user_prefs&data=%7B%7D"
              >
              > All of my posts have a parameter for ID, action, and data (sometimes
              > null). And this is exactly what I'm passing in as the fourth parameters.
              >
              > --- In ydn-javascript@yahoogroups.com, "tssha" tsha@ wrote:
              > >
              > > --- In ydn-javascript@yahoogroups.com, "jameschao122" jchao@ wrote:
              > > >
              > > > OK, seems like the problem is with the "Content-Type" header.
              > > >
              > > > By default, it is "application/x-www-form-urlencoded;
              > charset=UTF-8".
              > > >
              > > > When I change it to "application/x-www-form-urlencoded", it works.
              > > >
              > > > Does anybody know if this is the right way to do it or why the
              > default
              > > > value doesn't work??
              > > >
              > > > BTW, this is the code I'm doing to change the header:
              > > >
              > > > YAHOO.util.Connect.setDefaultPostHeader(false);
              > > > YAHOO.util.Connect.initHeader('Content-Type',
              > > > 'application/x-www-form-urlencoded');
              > >
              > > Interesting. Can you show the actual POST message you're sending as
              > > the fourth argument?
              > >
              > > Regards,
              > > Thomas
              > >
              >
            • tssha
              ... Without modifying any of the headers, I used Connection Manager to send the data you provided as follows: var data = encodeURI(
              Message 6 of 8 , May 31, 2007
              • 0 Attachment
                --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
                >
                > My post parameters look something like this:
                >
                > "id=1180625935031062&action=get_user_prefs&data=%7B%7D"
                >
                > All of my posts have a parameter for ID, action, and data (sometimes
                > null). And this is exactly what I'm passing in as the fourth parameters.

                Without modifying any of the headers, I used Connection Manager to
                send the data you provided as follows:

                var data = encodeURI(
                "id=1180625935031062&action=get_user_prefs&data={}"
                );
                var cObj = YAHOO.util.Connect.asyncRequest(
                'POST',
                'post.php,
                callback,
                data);

                The URI post.php will return the results of $_POST, and
                callback.success will write the results to a document. The following
                is the result:
                Array ( [id] => 1180625935031062 [action] => get_user_prefs [data] => {} )

                Can you talk a bit more about how your server entrypoint is configured?

                Regards,
                Thomas
              • jameschao122
                Hi Thomas, I m using Apache::ASP and it seems like the problem lies with that. According to
                Message 7 of 8 , Jun 1, 2007
                • 0 Attachment
                  Hi Thomas,

                  I'm using Apache::ASP and it seems like the problem lies with that.
                  According to
                  http://www.nabble.com/Content-type:-application-x-www-form-urlencoded--c\
                  harset%3Dutf-8-t1834467.html, it seems like Apache::ASP expects the
                  content type to be exactly "application-x-www-form-urlencoded", even
                  though the HTTP specs allow for more than that.

                  So, I'll just have to live with the workaround I've found. It would be
                  nice if there was a better API for changing this though (or am I using
                  the APIs incorrectly?). Honestly, a bit surprised that this Content-Type
                  header things hasn't been a problem for more people though...

                  Anyway, thanks for following up.

                  James


                  --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
                  >
                  > Also, I actually have to do the following to get the connection
                  manager
                  > to send the request with the correct header:
                  >
                  > YAHOO.util.Connect.resetDefaultHeaders();
                  > YAHOO.util.Connect.setDefaultPostHeader(false);
                  > YAHOO.util.Connect.initHeader('Content-Type',
                  > 'application/x-www-form-urlencoded', true);
                  >
                  >
                  > --- In ydn-javascript@yahoogroups.com, "jameschao122" jchao@ wrote:
                  > >
                  > > My post parameters look something like this:
                  > >
                  > > "id=1180625935031062&action=get_user_prefs&data=%7B%7D"
                  > >
                  > > All of my posts have a parameter for ID, action, and data (sometimes
                  > > null). And this is exactly what I'm passing in as the fourth
                  > parameters.
                  > >
                  > > --- In ydn-javascript@yahoogroups.com, "tssha" tsha@ wrote:
                  > > >
                  > > > --- In ydn-javascript@yahoogroups.com, "jameschao122" jchao@
                  wrote:
                  > > > >
                  > > > > OK, seems like the problem is with the "Content-Type" header.
                  > > > >
                  > > > > By default, it is "application/x-www-form-urlencoded;
                  > > charset=UTF-8".
                  > > > >
                  > > > > When I change it to "application/x-www-form-urlencoded", it
                  works.
                  > > > >
                  > > > > Does anybody know if this is the right way to do it or why the
                  > > default
                  > > > > value doesn't work??
                  > > > >
                  > > > > BTW, this is the code I'm doing to change the header:
                  > > > >
                  > > > > YAHOO.util.Connect.setDefaultPostHeader(false);
                  > > > > YAHOO.util.Connect.initHeader('Content-Type',
                  > > > > 'application/x-www-form-urlencoded');
                  > > >
                  > > > Interesting. Can you show the actual POST message you're sending
                  as
                  > > > the fourth argument?
                  > > >
                  > > > Regards,
                  > > > Thomas
                  > > >
                  > >
                  >
                • tssha
                  ... http://www.nabble.com/Content-type:-application-x-www-form-urlencoded--c ... You have the correct way to turn off the header and setting your own. // If
                  Message 8 of 8 , Jun 1, 2007
                  • 0 Attachment
                    --- In ydn-javascript@yahoogroups.com, "jameschao122" <jchao@...> wrote:
                    >
                    > Hi Thomas,
                    >
                    > I'm using Apache::ASP and it seems like the problem lies with that.
                    > According to
                    >
                    http://www.nabble.com/Content-type:-application-x-www-form-urlencoded--c\
                    > harset%3Dutf-8-t1834467.html, it seems like Apache::ASP expects the
                    > content type to be exactly "application-x-www-form-urlencoded", even
                    > though the HTTP specs allow for more than that.
                    >
                    > So, I'll just have to live with the workaround I've found. It would be
                    > nice if there was a better API for changing this though (or am I using

                    You have the correct way to turn off the header and setting your own.

                    // If you call resetDefaultHeaders here,
                    // you'll lose the custom header "X-Requested-With:XMLHttpRequest".
                    YAHOO.util.Connect.resetDefaultHeaders();

                    // The ability to turn the default POST header was to
                    // accommodated those who did not want to use this header
                    // as part of their POST request.
                    YAHOO.util.Connect.setDefaultPostHeader(false);

                    YAHOO.util.Connect.initHeader(
                    'Content-Type',
                    'application/x-www-form-urlencoded',
                    true
                    );

                    And, if you are interested:
                    http://sourceforge.net/tracker/index.php?func=detail&aid=1689122&group_id=165715&atid=836476

                    Regards,
                    Thomas
                  Your message has been successfully submitted and would be delivered to recipients shortly.