| 195 | |
| 196 | # Query the server via HTTP. |
| 197 | def queryHTTP (self, data): |
| 198 | result = None |
| 199 | |
| 200 | try: |
| 201 | self.con.putrequest("POST", "/") |
| 202 | self.con.putheader("Connection", "Keep-Alive") |
| 203 | self.con.putheader("User-Agent", "bitmessage") |
| 204 | self.con.putheader("Host", self.host) |
| 205 | self.con.putheader("Content-Type", "application/json") |
| 206 | self.con.putheader("Content-Length", str(len(data))) |
| 207 | self.con.putheader("Accept", "application/json") |
| 208 | authstr = "%s:%s" % (self.user, self.password) |
| 209 | self.con.putheader("Authorization", "Basic %s" % base64.b64encode (authstr)) |
| 210 | self.con.endheaders() |
| 211 | self.con.send(data) |
| 212 | try: |
| 213 | resp = self.con.getresponse() |
| 214 | result = resp.read() |
| 215 | if resp.status != 200: |
| 216 | raise Exception ("Namecoin returned status %i: %s", resp.status, resp.reason) |
| 217 | except: |
| 218 | logger.info("HTTP receive error") |
| 219 | except: |
| 220 | logger.info("HTTP connection error") |
| 221 | |
| 222 | return result |
| 223 | |
| 224 | # Helper routine sending data to the RPC server and returning the result. |
| 225 | def queryServer (self, data): |