8

I am trying to send a POST request to Meta using my account... but it's just not working very well. Using netcat, I was able to post one comment, but I have had no luck getting it to work with a PHP script.

I used a TCP monitor to capture the packets going back and forth between my browser and the server and managed to figure out some of it.

I am hoping someone on the team can help me here. Here is the POST request I'm sending:

POST /posts/51812/comments HTTP/1.1
Host: meta.stackoverflow.com
User-Agent: Mozilla/5.0
Accept: text/html, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: https://meta.stackexchange.com/questions/51812/
Cookie: usr=*********; somusr=*********
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 87

comment=This+comment+was+posted+from+someplace...&fkey=********

As you can see, a normal request. I have a few questions though:

  • What is the fkey parameter for? Where does it come from? What I have been doing thus far is fetching the page I want to post the comment on and using a RegEx to dig up the value.
  • Why does the server return the following and what does it mean?
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: /error?aspxerrorpath=/posts/51812/comments
Server: Microsoft-IIS/7.5
Date: Mon, 26 Jul 2010 01:44:07 GMT
Content-Length: 171
...

Any help or pointers would be appreciated.

4
  • Weird... this post has a downvote but it's not showing up. Commented Jul 26, 2010 at 1:56
  • 2
    Usually that means it's a flag (flags don't cause the summary reputation to be recalculated), but I don't know what this would've been flagged for Commented Jul 26, 2010 at 1:58
  • 1
    If posting with netcat works but not with PHP, doesn't that mean your PHP code is wrong? ergo, belongs on SO.
    – Ether
    Commented Jul 26, 2010 at 2:28
  • @Ether: No, the PHP code is syntactically correct. It's just that the SO web servers are sending funny responses to my requests. I can't seem to figure it out. Commented Jul 26, 2010 at 2:32

2 Answers 2

18

This is by design. We don't want bots posting here, and I won't be providing any information to assist in the creation of said bots.

11
  • 1
    @Jeff: I'm not making a bot. I'm trying to enhance StackMobile with write capabilities. Since there is no write-enabled API, I'm stuck using HTTP. Commented Jul 26, 2010 at 3:41
  • 8
    I think this is a good stance. Wait for a version of the API if you need to be able to post anything programatically.
    – jjnguy
    Commented Jul 26, 2010 at 3:42
  • 1
    I've almost got it going... I managed to post a couple comments now and again in a highly controlled setup. Commented Jul 26, 2010 at 3:43
  • 2
    @George just wait until the read/write API gets released
    – Earlz
    Commented Jul 26, 2010 at 3:43
  • 1
    @Justin, @Earlz: But I don't want to wait. You saw how long it took to get v1.0 out. Commented Jul 26, 2010 at 3:46
  • 18
    @george ok, but know that the entire team's day, every day, will be spent thinking up new ways to break you. Commented Jul 26, 2010 at 3:50
  • 2
    @Jeff: Don't worry, I'm ready to give up - the whole thing is so complicated. I've got shell windows, network traffic analyzers, scripts, and browser extensions all over my desktop. Sigh. I was hoping it would work. Commented Jul 26, 2010 at 3:58
  • 17
    Have (either of) you tried jQuery?
    – Andrew
    Commented Jul 26, 2010 at 7:28
  • 11
    First users ask for a mobile interface. Jeff says, "Nah. But we'll provide an API so you can write your own!". Now that someone actually did write one, the poor guy can't get support to make it post. Jeez!
    – user27414
    Commented Jul 26, 2010 at 17:15
  • @Andrew: ha ha ha! That won't help, of course. Commented Jul 26, 2010 at 21:01
  • 6
    @Jon: Thank you! I was beginning to think nobody cared that this won't work. I spent literally hours yesterday and the day before debugging HTTP requests, constructing a complex proxy, and banging my head against the wall. Commented Jul 26, 2010 at 21:03
2

Hi George. I hacked together something that works (pending any changes in StackOverflow's URLs and webpage structure). Here is the github: https://github.com/danchoi/ask_stack

My solution involves using SeleniumRC/Firefox as an intermediary between the command line tool and the StackOverflow server. This will let you post a question to StackOverflow from the unix command line.

By the way, my goal is not to faciliate spamming SO. I had a problem, which is that I wanted to write my StackOverflow questions in Vim and post them from the command line, and I hacked a solution.

2
  • Hmmm... that's neat. I'll have to take a look at it. Commented Apr 22, 2011 at 20:12
  • btW the tool only posts questions right now, but the same approach should work for comments. There is also apparently a way to keep things clean and run Firefox in a kind of "headless" mode using Xvfb so it doesn't open two Firefox windows each time.
    – dan
    Commented Apr 24, 2011 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .