Manipulating POST Data with Fiddler

8. June 2009

I like it when a new programming challenge crosses my mind. This is something i've never done before and it was a fun, quick challenge.

It all started with a simple twitter post that said 

So who's writing the scipt to automatically put 
#squarespace into every tweet for the next 30 days?

Since I use blu as my twitter client of choice (for now), my mind went immediately to how to manipulate the post to the server. I pulled up fiddler, a web debugging proxy to view and minipulate request and response data.

I made a post via blu while fiddler was running and looked for the request data.

 

I then checked the raw post to see how it was posting it to the server - in this case it was a simple HTTP POST. NOTE: this example image is after my modification. 

 

A little poking around and I found that you could manipulate the body and then send the manipulated version. Even programatically

I opened up my CustomRules.js by going to Rules -> Customize Rules and modified the OnbeforeRequest method and added:

 

		// intercept blu twitter posts and append data.
		if (oSession.HTTPMethodIs("POST") && (oSession.HostnameIs("twitter.com") || oSession.HostnameIs("www.twitter.com"))){
			
			var oBody = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
			
			oBody = oBody.replace("&source", Uri.EscapeDataString( " #squarespace") + "&source");
			
			oSession.utilSetRequestBody(oBody);
		}

Basically, i'm being really cheap here and doing a simple replace.

Line 4: Capturing the body
Line 6: Replacing &source (which is consistant) with a URI Properly Escaped string containing " #squarespace" and then the original &source parameter.
Line 8: Replacing the original body with the manipulated body.

Please Note, I know I am not checking the length of the string to make sure i'm within 140 characters; however, I don't care to use this, I just wanted to know if I could do it. This could easily be extended to check the length and only append if there is room. Let me know what you think via twitter or the comments below  - or post any enhancements you have to this little snippet!

General , , , ,

Comments

6/8/2009 10:35:15 AM #
I'm really impressed with your turnaround time getting this post out there! It's a very cool idea.  

I wonder if this could be useful for the facebook app that only posts tweets with the #fb tag. You could probably use another twitter client and only append it to tweets from that client. Definitely overkill to have to use 2 twitter clients just to avoid typing 4 characters (including the space).  Oh well, all ideas can't be breadwinners.
6/8/2009 10:40:43 AM #
What I think will happen is twitter clients will start (or should start) putting options in their client to say - check a box that says "post to facebook" and it appends the #fb tag. I'd be willing to put my time into an open source project that does such if anyone wants!
7/12/2009 11:39:26 AM #
Very interesting post - Might be old new, but it was new to me. Thanks.
Comments are closed