views:

34

answers:

0

Hi All, i'm using the Twisted web "HTTPClient" protocol to dialogue with a http server (using twisted app as a client), the problem is that most of my request do not accept my header. Is there some sort of way (maybe using certain libraries) to generate header?? I'll post some code so you can have a look

class Local(HTTPClient):
def generateHeaders(self, type=None):
    self.sendHeader('User-Agent', 'Twisted Web Client')
    if type:
        self.sendHeader('Content-Type', 'x-www-form-urlencoded')
    self.sendHeader('Accept', '*/*')
    self.sendHeader('Host', 'localhost')
    self.endHeaders()

def connectionMade(self):
    ## GENERATE ID
    self.userid= self.generateID()
    self.sendCommand('POST', '/chat/action=join&user=pirosb3')
    self.generateHeaders(type=True)

def dataReceived(self, data):
    print data

As you can see, i created a method that generates header for me, but not very efficient i must say, i always get error responses.

Anyone know a solution?

Thanks