2012-04-26 80 views
0

我使用此代碼...但我在我的代碼得到一些捲曲的錯誤..我得到一些捲曲的錯誤

function send_data($data) { 
      $url = ""; // URL to POST FORM. (Action of Form) 
      $url .= '?acx=' . urlencode('V2ViSnNvbkRldkFwbkBTaWdtYUFwbjpXZWIxMjMkSnNvbg==') . '&key=' . urlencode('QW51bWF0aGlVbmRhQFNpZ21hQXBuOlVuZHVBbnVtYXRoaQ=='); 
      $url .= '&impdata=' . urlencode('{"System":{"Client":"SigmaApn","ACX":"V2ViSnNvbkRldkFwbkBTaWdtYUFwbjpXZWIxMjMkSnNvbg==","KEY":"QW51bWF0aGlVbmRhQFNpZ21hQXBuOlVuZHVBbnVtYXRoaQ==","ClientIP":"74.117.104.99","Mode":"TEST"},"Module":{"Process":"BatchEnrollment","Version":"2.1.5","DataDefinition":[{"Name":"enrolment_queue","IncludeRecType":"false","Identifier":"sys_batch_no","Header":["batch_no","source","source_line","agent_code","premise_id","plan_group","request_date","enrol_type","cust_firstname","cust_lastname","phone1","cm_address1","cm_city","cm_state","cm_zip","life_support","cust_status","plan_id1","contract_ind","contract_type","calc_method","rate_type","adder1_rate","cust_bill_type","edi_bill_presenter"]}],"Data":[["Batch","BATCH","1","0","PREMISE1","R","10/28/2011","M","' . $data['personalinfo_first_name'] . '","' . $data['personalinfo_last_name'] . '","805","' . $data['service_address1'] . '","' . $data['service_city'] . '","' . $data['service_state'] . '","' . $data['service_zipcode'] . '","N","P","PN001","Y","MCP2","1","4","0.02","Default","ESP"]]}}'); 
      $url .= '&mode=' . urlencode('TEST'); 
      $headersVal = array("application/x-www-form-uriencoded"); 
      $myFile = "/tmp/isigma.txt"; 
      $fh = fopen($myFile, 'w') or die("can't open file"); 
      $ch = curl_init(); // Initialize a CURL session. 
      curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter. 
      curl_setopt($ch, CURLOPT_STDERR, $fh); 
      curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form 
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1'); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); 
      curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/iSIGMARootCA.crt"); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "/APN_Generic_JSON.pem"); 
      curl_setopt($ch, CURLOPT_SSLKEY, getcwd() . "/apnakey.pem"); 
      curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM"); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      $result = curl_exec($ch); // grab URL and pass it to the variable. 
      curl_close($ch); // close curl resource, and free system resources. 
      fclose($fh); 

      $res_array = json_decode($result, true); 

      if (!empty($result)) { 
       return $res_array; 
      } else { 
       echo "Curl Error" . curl_error($ch); 
      } 
     } 

感謝提前幫助..

+0

curl_error():276不是一個有效的cURL句柄資源 – 2012-04-26 13:14:57

回答

1

我使用此功能發佈數據。 您可以將關聯數組作爲第二個參數,第一個參數是要調用的網址。

private function postData($url, $data) { 

     $post_data = http_build_query($data); 
     $fp = tmpfile(); 
     $curl = curl_init(); 
     curl_setopt($curl, CURLOPT_URL, $url); 
     curl_setopt($curl, CURLOPT_TIMEOUT, 20); 
     curl_setopt($curl, CURLOPT_FILE, $fp); 
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
     curl_setopt($curl, CURLOPT_VERBOSE, 1); 
     curl_setopt($curl, CURLOPT_FAILONERROR, 1); 
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($curl, CURLOPT_COOKIEJAR, '/dev/null'); 

     $status = curl_exec($curl); 
     $response['http_code'] = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

     if ($status) { 
      $response['error'] = curl_error($curl); 
      $response['errno'] = curl_errno($curl); 
     } 

     curl_close($curl); 

     rewind($fp); 

     $response['data'] = ''; 
     while ($str = fgets($fp, 4096)) { 
      $response['data'] .= $str; 
     } 
     fclose($fp); 

     return $response['data']; 
    } 
+0

謝謝..我會試試這個.. – 2012-04-26 13:29:56