Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

postJSON's Content-Type #17

Closed
AdaHsu opened this issue Jul 19, 2011 · 5 comments
Closed

postJSON's Content-Type #17

AdaHsu opened this issue Jul 19, 2011 · 5 comments

Comments

@AdaHsu
Copy link

AdaHsu commented Jul 19, 2011

I tried to use postJSON() to post something to Plurk ( http://www.plurk.com ) with OAuth ( http://www.plurk.com/API/ ) but get the response "function arguments invalid. (2 missing, 0 additional)" .
So I checked the http request ( see https://lh4.googleusercontent.com/-6QJVff5Rlvw/TiUEOH-0wnI/AAAAAAAADBo/9RSSy9gpKJg/s912/postJSON-2.png ) and it's because postJSON() send the wrong content-type "text/plain" , can I use postJSON() with content-type = 'application/x-www-form-urlencoded' or must use oauth.request() to do what I want to do ?

=== code as bellow ===
$( '#plurkAdd' ).click( function() {

  var plurk_content = $( '#plurk_content' ).val();
  if( plurk_content != '' ) {
    var params = new Object();
    params.content = plurk_content;
    params.qualifier = 'says';
    params.lang = 'tr_ch';

    // using postJSON() 
    oauth.postJSON( 
        config.TimelineAddPlurkUrl
      , params
      , function( json ) {
        console.log( "Plurk Successed !" );
        console.log( json );
      }
      , function( json ) {
        console.log( "Plurk Failure !" );
        console.error( json );
      } );

    /*
    oauth.request({'method': 'POST'
      , 'headers': { 'Content-Type': 'application/x-www-form-urlencoded' }
      , 'url': config.TimelineAddPlurkUrl
      , 'data': params
      , 'success': function( json ) {
          console.log( "Plurk Successed !" );
          console.log( json );
        }
      , 'failure': function( json ) {
          console.log( "Plurk Failure !" );
          console.error( json );
        } 
      });
    */        

  }          
@bytespider
Copy link
Owner

Does .post() do what you want it to? Your right about the header, it should have been application/json.

@zhusee2
Copy link

zhusee2 commented Jul 29, 2011

Here I've got a similar problem, too.

I use .request() to send a header with content type application/json to Google's OAuth service. It worked fine in 1.3, but now fails in 1.3.1. After some research, I found it's caused by the conditional expression at line 407. It detects that I manually send a Content-Type header and then blocks the init of signatureData array.

So maybe adding a content type to .getJSON() and .postJSON() will be a good way to deal with all this, I guess?

Update: I found that in my case, only adding url.query.toObject() to signatureData can pass Google's service; adding data to signatureData will also cause failure like adding nothing to signatureData… not sure if it's related to the spec you mention at line 407.

@bytespider
Copy link
Owner

The spec says the params are signed if the content type is single part and url-form-encoded. I dont think application/json meets both those. I could be wrong but i'll revert the change for the time being.

On 29 Jul 2011, at 02:40, zhusee2reply@reply.github.com wrote:

Here I've got a similar problem, too.

I use .request() to send a header with content type application/json to Google's OAuth service. It worked fine in 1.3, but now fails in 1.3.1. After some research, I found it's caused by the conditional expression at line 407. It detects that I manually send a Content-Type header and then blocks the init of signatureData array.

So maybe adding a content type to .getJSON() and .postJSON() will be a good way to deal with all this, I guess?

Reply to this email directly or view it on GitHub:
#17 (comment)

@zhusee2
Copy link

zhusee2 commented Jul 29, 2011

Yeah, you're right about the spec. Thanks for the explanation.
I'll find some other ways to solve my issue, so you don't have to do the reversion :)

@bytespider
Copy link
Owner

Im going to close this for the time being

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants