Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:18:41+00:00 2026-06-18T14:18:41+00:00

I am trying to implement a Firefox Extension which modify the POST request data.

  • 0

I am trying to implement a Firefox Extension which modify the POST request data.

Code follows, it fails where marked “Fails here!!!“

Any insight would be helpful.

    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

    var newData = "test 123";
    function LOG(msg) {
        var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
                                     .getService(Components.interfaces.nsIConsoleService);
        consoleService.logStringMessage(msg);
    }

    function CMP() {
        this.registered = false;
        this.register();
    }

    CMP.prototype = {

        register: function() {
            if (this.registered == false) {
                var observerService = Components.classes["@mozilla.org/observer-service;1"]
                    .getService(Components.interfaces.nsIObserverService);
                observerService.addObserver(this, "http-on-modify-request", false);
                this.registered = true;
            }
        },

        observe: function(subject, topic, data) 
        {
            LOG("Inside observe");
            if (topic == "http-on-modify-request") 
            {
                LOG("TOPIC is http-on-modify-request");
                var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);

                if(httpChannel.requestMethod == "POST"){
                    LOG("Inside POST")
                    var uploadChannel = httpChannel.QueryInterface(Components.interfaces.nsIUploadChannel);
                    //var uploadChannelStream = uploadChannel.uploadStream; 

Modify the data here. Here for testing i am passing “test 123” as new data

                    var newStringInputStream = Components.classes['@mozilla.org/io/string-input-stream;1'].createInstance(Components.interfaces.nsIStringInputStream);
                    newStringInputStream.setData(newData,newData.length);
                    LOG("set data in newStringInputStream!!");

                    uploadChannel.setUploadStream(newStringInputStream, "text/plain", -1 );// Fails here!!!
                    httpChannel.requestMethod = "POST";
                    LOG("upload DONE!!")  
                }   
            }
        },

        QueryInterface : function(aIID) {
        if (aIID.equals(Components.interfaces.nsISupports) ||
            aIID.equals(Components.interfaces.nsIObserver))
          return this;
        throw Components.results.NS_NOINTERFACE;
        },

        unregister: function() {
            var observerService = Components.classes["@mozilla.org/observer-service;1"]
                .getService(Components.interfaces.nsIObserverService);
            observerService.removeObserver(this, "http-on-modify-request");
        },

        classID: Components.ID('{F799F47E-ABA5-4AF1-B8F2-BD74E3E5BCC0}'),
        QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver])
    };

    if (XPCOMUtils.generateNSGetFactory)
    {
      var NSGetFactory = XPCOMUtils.generateNSGetFactory([CMP]);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:18:42+00:00Added an answer on June 18, 2026 at 2:18 pm

    Fixed it by changing by following in the above code. Main change was in setting modified data in httpChannel.uploadStream.

    Hope this helps someone!

    var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
                if(httpChannel.requestMethod == "POST")
                {
                    LOG("Inside POST")
                    var uploadChannel = httpChannel.QueryInterface(Components.interfaces.nsIUploadChannel); 
                    var newStringInputStream = Components.classes['@mozilla.org/io/string-input-stream;1'].createInstance(Components.interfaces.nsIStringInputStream);
                    newStringInputStream.setData(newData,newData.length);
                    var uploadChannelStream = uploadChannel.uploadStream;
                    uploadChannelStream = uploadChannelStream.QueryInterface(Components.interfaces.nsISeekableStream).seek(Components.interfaces.nsISeekableStream.NS_SEEK_SET, 0);
                    httpChannel.uploadStream.QueryInterface(Components.interfaces.nsIMIMEInputStream);
                    httpChannel.uploadStream.setData(newStringInputStream);
                    LOG("Done POST")
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying implement the Data transformation using Reflection 1 example in my code.
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
I am trying implement a most recent widget into my tumblr post. So far,
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement this basic example found here : under the section titled
I'm trying to implement HTML5's drag and drop in my app, but Firefox is
I'm getting the following error message in Chrome and firefox while trying to implement
I'm trying to implement this code to have different files to load for german,
I'm trying to implement file upload functionality in the iPhone app. Server code is
Here's a long one. I'm trying to implement horizontal scrolling in my site. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.