2016-03-02 77 views
0

我想將我的價值傳遞給salesforce api。我正在獲取貸款申請編號,正如您在最後一行錯誤中所看到的。但它也顯示「失敗,狀態200」。他們在代碼中改變了一些東西,或者只是爲了獲得它而已。我還想在前端顯示該貸款申請號。它的語法是什麼。我已經嘗試過PHP的數組語法,但它不會工作。錯誤是如下爲什麼我得到這個錯誤?他們應該改變什麼?

Error: call to URL https://cs31.salesforce.com/services/apexrest/CreateLoan/ failed with status 200, response HTTP/1.1 200 OK Date: Tue, 01 Mar 2016 12:31:56 GMT Set-Cookie: BrowserId=cLMf4KPnTvqxcif286fSRQ;Path=/;Domain=.salesforce.com;Expires=Sat, 30-Apr-2016 12:31:56 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked "success: Loan Application Number - 804326966", curl_error , curl_errno 0 

我的代碼如下

<?php session_start(); 
$json=$_SESSION['json']; 
$details=json_decode($json); 
//var_dump($details); 
$name='LoanCreationService'; 
$instance_url='https://cs31.salesforce.com/services/apexrest/CreateLoan/'; 
$access_token = $details->{'access_token'}; 
$message=create_account($name, $instance_url, $access_token); 
//echo $message->{'message'}; 
function create_account($name, $instance_url, $access_token) { 
    $url = $instance_url; 
    //$content = json_encode(array("Name" => $name)); 
    $content=$_SESSION['content'];; 
    //echo $content; 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_HEADER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, 
      array("Authorization: OAuth $access_token", 
       "Content-type: application/json")); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

    $json_response = curl_exec($curl); 
    //echo $json_response; 
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if ($status != 201) { 
     die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); 
    } 

    //echo "HTTP status $status creating account<br/><br/>"; 

    curl_close($curl); 

    $response = json_decode($json_response, true); 

    echo $id = $response["id"]; 



    return $id; 
} 
?> 

回答

0

你正在殺死它的代碼,因爲您要查找的狀態是201,並請求返回200,你可以看到在您返回的錯誤消息。如果需要,嘗試將狀態設置爲201。

0

狀態200確定,表示您的請求已成功,您已獲得"success: Loan Application Number - 804326966"。請參閱w3 doc

可能您可以試試這個嗎?

$json_response = curl_exec($curl); 
    //echo $json_response; 
    $status = curl_getinfo($curl); 

if ($output === false || $status ['http_code'] != 200) { 
    $output = "No cURL data returned for $url [". $status ['http_code']. "]"; 
    if (curl_error($curl)) 
    $output .= "\n". curl_error($curl); 
    } 
//now check the resopose 

var_dump($json_response); 
    //echo "HTTP status $status creating account<br/><br/>"; 
    $key = "success: Loan Application Number -"; 
    $pos = strpos($json_response, $key); 
    //echo $pos; 
    $appNumber = substr($json_response,strlen($key)+ $pos,strlen($json_response)); 
    echo $appNumber; 
    curl_close($curl); 
    $response = json_decode($json_response, true); 

echo $id = $response["id"]; 
+0

感謝您的回覆。您能否告訴我如何從整個回覆中只提取貸款申請編號? –