Rest API Status Update Authorization Error



I am building a twitter api rest client. I need to be able to send direct messages and or post a status update for a user. I am manually building the authorization header myself which works great most of the time. If the message text contains any reserved RFC3986 characters my api call fails indicating bad authentication data. The string below for instance for a status update causes this error:

“This is my new status @myhandle

I have attempted to avoid encoding the @ sign altogether and still no luck. Excluding it from the status parameter allows the request to go through as expected. The same goes for an ! mark in tweet text. I am using javascript and the function I am using to encode the parameters is :

 percentEncode: function(value) { //RFC3986
    return encodeURIComponent(value).replace(/[!'()*]/g, function(c) {
      return '%' + c.charCodeAt(0).toString(16);

I was originally using the encodeURIComponent() function by itself but this link indicated that to conform to RFC3986 I need to add the replace function for reserved characters. Does anyone have any ideas / have any experience with this issue and could point me in the right direction. Been wracking my brain trying to figure this out but cannot seem to :(.

Thanks All