PHP Curl Fucntion无法在ajax调用中工作?

时间:2017-10-05 11:30:52

标签: php jquery curl drupal

我发送Xml请求并使用CURL请求函数获取响应。如果我发送静态值我得到了响应但是如果我使用PHP文件发送动态值,则响应无法得到它。我可以知道我错在哪里

包括2个代码

<?xml version="1.0" encoding="UTF-8"?>
            <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
               <SOAP:Body>
                  <serve xmlns="http://schemas.cordys.com/gateway/Provider">
                    <SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
                        <Session>
                          <SessionData xmlns="XXXX">
                            <Index>1</Index>
                            <InitTime>Thu, 05 Oct 17 15:55:44 +0530</InitTime>
                            <UserName>XXXXX</UserName>
                            <Password>XXXXX</Password>
                            <OrderNo>NA</OrderNo>
                            <QuoteNo>NA</QuoteNo>
                            <Route>INT</Route>
                            <Contract>XXX</Contract>
                            <Channel>XXX</Channel>
                            <TransactionType>Quote</TransactionType>
                            <TransactionStatus>Fresh</TransactionStatus>
                            <ID>XXXXXX</ID>
                            <UserAgentID>XXXX</UserAgentID>
                            <Source>XXXX</Source>
                            <IsCCUser>N</IsCCUser>
                          </SessionData>
                          <tns:Vehicle xmlns:tns="XXXXX">
                            <tns:TypeOfBusiness>TR</tns:TypeOfBusiness>
                            <tns:AccessoryInsured>N</tns:AccessoryInsured>
                            <tns:AccessoryValue>0</tns:AccessoryValue>
                            <tns:AntiTheftDevice>N</tns:AntiTheftDevice>
                            <tns:BiFuelKit>
                              <tns:IsBiFuelKit>N</tns:IsBiFuelKit>
                              <tns:BiFuelKitValue>0</tns:BiFuelKitValue>
                              <tns:ExternallyFitted>N</tns:ExternallyFitted>
                            </tns:BiFuelKit>
                            <tns:DateOfRegistration></tns:DateOfRegistration>
                            <tns:RiskType>FTW</tns:RiskType>
                            <tns:Make>HONDA MOTORS</tns:Make>
                            <tns:Model>ACTIVA</tns:Model>
                            <tns:FuelType>P</tns:FuelType>
                            <tns:Variant>3G</tns:Variant>
                            <tns:IDV>20202</tns:IDV>
                            <tns:EngineNo></tns:EngineNo>
                            <tns:ChasisNo></tns:ChasisNo>
                            <tns:DriveExperiance />
                            <tns:NoOfDrivers />
                            <tns:ParkingType />
                            <tns:AnnualMileage />
                            <tns:YoungestDriverAge />
                            <tns:PaidDriver />
                            <tns:VehicleAge>4</tns:VehicleAge>
                            <tns:CC>109</tns:CC>
                            <tns:PlaceOfRegistration>Mumbai Navi Mumbai</tns:PlaceOfRegistration>
                            <tns:SeatingCapacity>2</tns:SeatingCapacity>
                            <tns:VehicleExtraTag01 />
                            <tns:RegistrationNo></tns:RegistrationNo>
                            <tns:ExShowroomPrice>51800</tns:ExShowroomPrice>
                            <tns:DateOfManufacture>2014</tns:DateOfManufacture>
                          </tns:Vehicle>
                          <tns:Quote xmlns:tns="XXXXXX">
                            <PolicyTenure>1</PolicyTenure>
                            <tns:ExistingPolicy>
                              <tns:Claims>0</tns:Claims>
                              <tns:PolicyType>Comprehensive</tns:PolicyType>
                              <tns:EndDate></tns:EndDate>
                              <tns:NCB>0</tns:NCB>
                              <tns:PolicyNo></tns:PolicyNo>
                              <tns:InsuranceCompany></tns:InsuranceCompany>
                            </tns:ExistingPolicy>
                            <tns:PolicyStartDate>2017-10-06T00:00:00.000</tns:PolicyStartDate>
                            <tns:Deductible>0</tns:Deductible>
                            <tns:PAFamilySI>100000</tns:PAFamilySI>
                            <tns:AgentNumber>2C000002</tns:AgentNumber>
                            <tns:DealerId>619</tns:DealerId>
                            <tns:Premium>
                              <tns:Discount />
                            </tns:Premium>
                            <tns:SelectedCovers>
                             <tns:CarDamageSelected>true</tns:CarDamageSelected>
                             <tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
                             <tns:PADriverSelected>true</tns:PADriverSelected>
                             <tns:ZeroDepriciationSelected>false</tns:ZeroDepriciationSelected>
                              <tns:RoadsideAssistanceSelected>false</tns:RoadsideAssistanceSelected>
                              <tns:InvoicePriceSelected>false</tns:InvoicePriceSelected>
                              <tns:InvoicePriceCoverAmount />
                              <tns:PAFamilyPremiumSelected>false</tns:PAFamilyPremiumSelected>
                              <tns:HospitalCashSelected>false</tns:HospitalCashSelected>
                              <tns:MedicalExpensesSelected>false</tns:MedicalExpensesSelected>
                              <tns:AmbulanceChargesSelected>false</tns:AmbulanceChargesSelected>
                              <tns:CosumableCoverSelected>false</tns:CosumableCoverSelected>
                              <tns:HydrostaticLockSelected>false</tns:HydrostaticLockSelected>
                              <tns:KeyReplacementSelected>false</tns:KeyReplacementSelected>
                              <tns:NoClaimBonusSameSlabSelected>false</tns:NoClaimBonusSameSlabSelected>
                              <tns:EngineGearBoxProtectionSelected>false</tns:EngineGearBoxProtectionSelected>
                            </tns:SelectedCovers>
                            <tns:PolicyEndDate>2018-10-05T23:59:59.000</tns:PolicyEndDate>
                          </tns:Quote>
                          <tns:Client xmlns:tns="XXX">
                            <tns:ClientType>Individual</tns:ClientType>
                            <tns:CltDOB></tns:CltDOB>
                            <tns:FinancierDetails>
                              <tns:IsFinanced>0</tns:IsFinanced>
                              <tns:InstitutionName></tns:InstitutionName>
                              <tns:InstitutionCity></tns:InstitutionCity>
                            </tns:FinancierDetails>
                            <tns:GivName>BharatiTwo1507199144</tns:GivName>
                            <tns:ClientExtraTag01>MAHARASHTRA</tns:ClientExtraTag01>
                            <tns:CityOfResidence>Mumbai Navi Mumbai</tns:CityOfResidence>
                            <tns:EmailID>dfgkgj@KJhj.com</tns:EmailID>
                            <tns:MobileNo>9865325896</tns:MobileNo>
                            <tns:LandLineNo></tns:LandLineNo>
                            <tns:SurName></tns:SurName>
                            <tns:CltSex></tns:CltSex>
                            <tns:Marryd></tns:Marryd>
                            <tns:Occupation></tns:Occupation>
                            <tns:CltAddr01></tns:CltAddr01>
                            <tns:CltAddr02></tns:CltAddr02>
                            <tns:CltAddr03></tns:CltAddr03>
                            <tns:City></tns:City>
                            <tns:State></tns:State>
                            <tns:PinCode></tns:PinCode>
                            <tns:Nominee>
                              <tns:Name></tns:Name>
                              <tns:Age></tns:Age>
                              <tns:Relationship></tns:Relationship>
                              <tns:Appointee></tns:Appointee>
                              <tns:AppointeeRelation></tns:AppointeeRelation>
                            </tns:Nominee>
                            <tns:RegistrationZone>B</tns:RegistrationZone>
                            <GstinNo>GSTinNO</GstinNo>
                          </tns:Client>
                          <Payment>
                            <PaymentMode />
                            <PaymentType />
                            <TxnReferenceNo />
                            <TxnAmount />
                            <TxnDate />
                            <BankCode />
                            <InstrumentAmount />
                          </Payment>
                        </Session>
                    </SessionDoc>
                  </serve>
               </SOAP:Body>
            </SOAP:Envelope>';
$headers = array(
        "Content-type: application/xml",
        "Content-length: " . strlen($xml),
        "Connection: close",
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    echo "<pre>";
    echo  $data = curl_exec($ch); exit;

这是使用我们传递的PHP值进行动态生成的代码

<?xml version="1.0" encoding="UTF-8"?>
            <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
               <SOAP:Body>
                  <serve xmlns="http://schemas.cordys.com/gateway/Provider">
                    <SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
                        <Session>
                          <SessionData xmlns="XXX">
                            <Index>'.$stage.'</Index>
                            <InitTime>'.$current_date.'</InitTime>
                            <UserName>XXXXX</UserName>
                            <Password>XXXX</Password>
                            <OrderNo>'.$order_no.'</OrderNo>
                            <QuoteNo>'.$quote_no.'</QuoteNo>
                            <Route>INT</Route>
                            <Contract>MTR</Contract>
                            <Channel>XXXX</Channel>
                            <TransactionType>Quote</TransactionType>
                            <TransactionStatus>Fresh</TransactionStatus>
                            <ID>XXXXX</ID>
                            <UserAgentID>2C000002</UserAgentID>
                            <Source>2C000002</Source>
                            <IsCCUser>N</IsCCUser>
                          </SessionData>
                          <tns:Vehicle xmlns:tns="XXX">
                            <tns:TypeOfBusiness>'.$bis_type.'</tns:TypeOfBusiness>
                            <tns:AccessoryInsured>'.$access_ins.'</tns:AccessoryInsured>
                            <tns:AccessoryValue>'.$access_val.'</tns:AccessoryValue>
                            <tns:AntiTheftDevice>'.$anti_thfdev.'</tns:AntiTheftDevice>
                            <tns:BiFuelKit>
                              <tns:IsBiFuelKit>'.$fuel_kit.'</tns:IsBiFuelKit>
                              <tns:BiFuelKitValue>'.$fuel_kit_val.'</tns:BiFuelKitValue>
                              <tns:ExternallyFitted>'.$ext_fit.'</tns:ExternallyFitted>
                            </tns:BiFuelKit>
                            <tns:DateOfRegistration>'.$veh_reg_date.'</tns:DateOfRegistration>
                            <tns:RiskType>'.$risktype.'</tns:RiskType>
                            <tns:Make>'.$make.'</tns:Make>
                            <tns:Model>'.$model.'</tns:Model>
                            <tns:FuelType>'.$fuel_type.'</tns:FuelType>
                            <tns:Variant>'.$variant.'</tns:Variant>
                            <tns:IDV>'.$idv.'</tns:IDV>
                            <tns:EngineNo>'.$engine_no.'</tns:EngineNo>
                            <tns:ChasisNo>'.$chasis_no.'</tns:ChasisNo>
                            <tns:DriveExperiance />
                            <tns:NoOfDrivers />
                            <tns:ParkingType />
                            <tns:AnnualMileage />
                            <tns:YoungestDriverAge />
                            <tns:PaidDriver />
                            <tns:VehicleAge>'.$veh_age.'</tns:VehicleAge>
                            <tns:CC>'.$cc.'</tns:CC>
                            <tns:PlaceOfRegistration>'.$place_reg.'</tns:PlaceOfRegistration>
                            <tns:SeatingCapacity>'.$seating.'</tns:SeatingCapacity>
                            <tns:VehicleExtraTag01 />
                            <tns:RegistrationNo>'.$veh_number.'</tns:RegistrationNo>
                            <tns:ExShowroomPrice>'.$x_shw_prc.'</tns:ExShowroomPrice>
                            <tns:DateOfManufacture>'.$mnf_year.'</tns:DateOfManufacture>
                          </tns:Vehicle>
                          <tns:Quote xmlns:tns="XXXX">
                            <PolicyTenure>'.$policy_tenure.'</PolicyTenure>
                            <tns:ExistingPolicy>
                              <tns:Claims>0</tns:Claims>
                              <tns:PolicyType>Comprehensive</tns:PolicyType>
                              <tns:EndDate>'.$ext_policy_enddate.'</tns:EndDate>
                              <tns:NCB>'.$ncb_val.'</tns:NCB>
                              <tns:PolicyNo>'.$policy_no.'</tns:PolicyNo>
                              <tns:InsuranceCompany>'.$ins_cmp.'</tns:InsuranceCompany>
                            </tns:ExistingPolicy>
                            <tns:PolicyStartDate>'.$policy_stdate.'</tns:PolicyStartDate>
                            <tns:Deductible>'.$deductable.'</tns:Deductible>
                            <tns:PAFamilySI>100000</tns:PAFamilySI>
                            <tns:AgentNumber>2C000002</tns:AgentNumber>
                            <tns:DealerId>619</tns:DealerId>
                            <tns:Premium>
                              <tns:Discount />
                            </tns:Premium>
                            <tns:SelectedCovers>
                             <tns:CarDamageSelected>true</tns:CarDamageSelected>
                             <tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
                             <tns:PADriverSelected>true</tns:PADriverSelected>
                             <tns:ZeroDepriciationSelected>'.$addons_list['DEPC'].'</tns:ZeroDepriciationSelected>
                              <tns:RoadsideAssistanceSelected>'.$addons_list['RSAC'].'</tns:RoadsideAssistanceSelected>
                              <tns:InvoicePriceSelected>'.$addons_list['INPC'].'</tns:InvoicePriceSelected>
                              <tns:InvoicePriceCoverAmount />
                              <tns:PAFamilyPremiumSelected>'.$addons_list['PAFamily'].'</tns:PAFamilyPremiumSelected>
                              <tns:HospitalCashSelected>'.$addons_list['HOSP'].'</tns:HospitalCashSelected>
                              <tns:MedicalExpensesSelected>'.$addons_list['MEDI'].'</tns:MedicalExpensesSelected>
                              <tns:AmbulanceChargesSelected>'.$addons_list['AMBC'].'</tns:AmbulanceChargesSelected>
                              <tns:CosumableCoverSelected>'.$addons_list['CONC'].'</tns:CosumableCoverSelected>
                              <tns:HydrostaticLockSelected>'.$addons_list['HYLC'].'</tns:HydrostaticLockSelected>
                              <tns:KeyReplacementSelected>'.$addons_list['KEYC'].'</tns:KeyReplacementSelected>
                              <tns:NoClaimBonusSameSlabSelected>'.$addons_list['NCBS'].'</tns:NoClaimBonusSameSlabSelected>
                              <tns:EngineGearBoxProtectionSelected>'.$addons_list['EGBP'].'</tns:EngineGearBoxProtectionSelected>
                            </tns:SelectedCovers>
                            <tns:PolicyEndDate>'.$policy_endate.'</tns:PolicyEndDate>
                          </tns:Quote>
                          <tns:Client xmlns:tns="XXXX">
                            <tns:ClientType>Individual</tns:ClientType>
                            <tns:CltDOB>'.$clnt_dob.'</tns:CltDOB>
                            <tns:FinancierDetails>
                              <tns:IsFinanced>'.$is_fin.'</tns:IsFinanced>
                              <tns:InstitutionName>'.$fin_name.'</tns:InstitutionName>
                              <tns:InstitutionCity>'.$fin_city.'</tns:InstitutionCity>
                            </tns:FinancierDetails>
                            <tns:GivName>'.$first_name.'</tns:GivName>
                            <tns:ClientExtraTag01>'.$reg_state.'</tns:ClientExtraTag01>
                            <tns:CityOfResidence>'.$rto.'</tns:CityOfResidence>
                            <tns:EmailID>'.$email_id.'</tns:EmailID>
                            <tns:MobileNo>'.$mobile_no.'</tns:MobileNo>
                            <tns:LandLineNo>'.$emg_cnt_no.'</tns:LandLineNo>
                            <tns:SurName>'.$last_name.'</tns:SurName>
                            <tns:CltSex>'.$gender.'</tns:CltSex>
                            <tns:Marryd>'.$martial_status.'</tns:Marryd>
                            <tns:Occupation>'.$occup.'</tns:Occupation>
                            <tns:CltAddr01>'.$addr1.'</tns:CltAddr01>
                            <tns:CltAddr02>'.$addr2.'</tns:CltAddr02>
                            <tns:CltAddr03>'.$landmark.'</tns:CltAddr03>
                            <tns:City>'.$city.'</tns:City>
                            <tns:State>'.$state.'</tns:State>
                            <tns:PinCode>'.$pincode.'</tns:PinCode>
                            <tns:Nominee>
                              <tns:Name>'.$nom_name.'</tns:Name>
                              <tns:Age>'.$nom_age.'</tns:Age>
                              <tns:Relationship>'.$nom_rel.'</tns:Relationship>
                              <tns:Appointee>'.$nom_apnt.'</tns:Appointee>
                              <tns:AppointeeRelation>'.$nom_apnt_rel.'</tns:AppointeeRelation>
                            </tns:Nominee>
                            <tns:RegistrationZone>'.$reg_zone.'</tns:RegistrationZone>
                            <GstinNo></GstinNo>
                          </tns:Client>
                          <Payment>
                            <PaymentMode />
                            <PaymentType />
                            <TxnReferenceNo />
                            <TxnAmount />
                            <TxnDate />
                            <BankCode />
                            <InstrumentAmount />
                          </Payment>
                        </Session>
                    </SessionDoc>
                  </serve>
               </SOAP:Body>
            </SOAP:Envelope>';
            $headers = array(
        "Content-type: application/xml",
        "Content-length: " . strlen($xml),
        "Connection: close",
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $data = curl_exec($ch);

我在这里做错了。请清除我

0 个答案:

没有答案