diff --git a/tests/services.test b/tests/services.test
index d73bb32..74ca2e6 100644
--- a/tests/services.test
+++ b/tests/services.test
@@ -2,6 +2,8 @@
 
 class ServicesWebTestCase extends DrupalWebTestCase {
 
+  protected $previousExecHadInfile = FALSE;
+
   public function setUp() {
     $args = func_get_args();
 
@@ -720,6 +722,16 @@ class ServicesWebTestCase extends DrupalWebTestCase {
       // not overwritten by Curl.
       $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
     }
+
+    if ($this->previousExecHadInfile) {
+      // If the previous exec used CURLOPT_INFILE, we have to reinitialize curl
+      // to loose the option, as to not cause curl to complain that the file has
+      // disappeared.
+      curl_close($this->curlHandle);
+      unset($this->curlHandle);
+      $this->curlInitialize();
+    }
+    $this->previousExecHadInfile = isset($curl_options[CURLOPT_INFILE]);
     curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
 
     if (!$redirect) {
