Example #1
0
 def urlPost(self, url, postBody):
     try:
         client = BasicHttpClient(url)
         post = PostMethod(url)
         #######
         # Which will work?
         #post.setRequestBody(postBody)
         post.addParameter("xml", postBody)
         #######
         sharedSecret = self.doiConfig("sharedSecret")
         if (sharedSecret):
             apiKey = self.doiConfig("apiKey")
             if (apiKey is not None):
                 client.authenticate(apiKey, sharedSecret)
             else:
                 raise EnvironmentError("Cannot have shared secret without an api key")
         code = client.executeMethod(post)
         if str(code) == "302":
             locationHeader = post.getResponseHeader("location")
             if locationHeader is not None:
                 redirectLocation = locationHeader.getValue()
                 self.log.info("302 Redirection was requested: '{}'", redirectLocation)
                 ##return self.urlPost(redirectLocation, postBody)
         body = str(post.getResponseBodyAsString()).strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)