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;
}
?>
4

2 回答 2

0

状态 200 OK,表示您的请求成功并且您已经获得"success: Loan Application Number - 804326966". 请参阅w3 文档

也许你可以试试这个?

$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"];
于 2016-03-02T06:03:43.113 回答
0

您正在代码中杀死它,因为您查找的状态是 201 并且请求返回 200,正如您在返回的错误消息中看到的那样。如果需要,请尝试将状态设置为 201。

于 2016-03-02T05:42:26.683 回答