PHP CURL在从curl命令转换时不工作

ryevplcw  于 2022-12-17  发布在  PHP
关注(0)|答案(1)|浏览(169)

我有一个curl命令,它在终端工作正常,并希望在PHP代码转换,但它给415不支持的媒体类型错误。
curl 命令:

curl --location 
--request POST 'https://securegw-uat.starhealth.in/api/proposal-service/v2/ckyc/generate' 
--header 'APIKEY: 25861f5655bd4640b5518ceb2bfb5f94' 
--header 'SECRETKEY: beec6bf3afff4efdab1f6a80d8601fbf' 
--form 'bodyJson="{\"ckycId\":10036801290855,\"idOrAddressProofDocumentId\": 1,\"titleId\": 1,\"firstName\": \"Swadhin\",\"middleName\": \"\",\"lastName\": \"Dhal\",\"genderId\": 1,\"birthdate\": \"November 01, 1973\",\"occupationId\": 1,\"residentialStatusId\": 1,\"pan\": \"BLAPT0864M\",\"familyRelationshipId\": 3,\"familyMemberTitleId\": 2,\"familyMemberFirstName\": \"Rachita\",\"familyMemberLastName\": \"Dhal\",\"addressLineOne\": \"No. 20\",\"addressLineTwo\": \"Nehru Street\",\"cityName\": \"Triplicane\",\"districtName\": \"Chennai\",\"stateCode\": \"TN\",\"countryCode\": \"IN\",\"postalCode\": \"600005\",\"incomeSourceId\": 1,\"isAnyonePEP\": 0}";type=application/json'
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://securegw-uat.starhealth.in/api/proposal-service/v2/ckyc/generate',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => array('bodyJson' => '{
    "ckycId": 10036801290855,
    "idOrAddressProofDocumentId": 1,
    "idOrAddressProofDocumentNumber": "1234",
    "titleId": 1,
    "firstName": "Swadhin",
    "middleName": "",
    "lastName": "Dhal",
    "genderId": 1,
    "birthdate": "November 01, 1973",
    "occupationId": 1,
    "residentialStatusId": 1,
    "pan": "BLAPT0864M",
    "familyRelationshipId": 3,
    "familyMemberTitleId": 2,
    "familyMemberFirstName": "Rachita",
    "familyMemberLastName": "Dhal",
    "addressLineOne": "No. 20",
    "addressLineTwo": "Nehru Street",
    "cityName": "Triplicane",
    "districtName": "Chennai",
    "stateCode": "TN",
    "countryCode": "IN",
    "postalCode": "600005",
    "incomeSourceId": 1,
    "isAnyonePEP": 0
}'),
    CURLOPT_HTTPHEADER => array(
        'Content-Type: multipart/form-data',
        'APIKEY: 25861f5655bd4640b5518ceb2bfb5f94',
        'SECRETKEY: beec6bf3afff4efdab1f6a80d8601fbf'
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;`
628mspwn

628mspwn1#

请尝试将标题指定为--header 'Content-Type:多部分/表单数据“。

相关问题