2017-11-06 1 views
0

URL 끝점에 XML 문자열을 게시해야합니다. 필자는 JavaScript를 통해이 작업을 수행하는 것에 익숙하지만, PHP를 사용하는 것은 아닙니다. 나는 결국 WordPress Gravity Form 변수를 데이터에 추가 할 예정이지만 현재는 정적으로 테스트하고 있습니다.PHP를 통해 XML 문자열 게시

나는 cURL 오류가 발생하지만 문제를 해결하는 방법에 대해서는 조금 불확실합니다.

다음은 오류입니다. 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

<?php 
 
/* print the contents of a url */ 
 
function print_r_xml($arr,$wrapper = 'EstimateRequest',$cycle = 1) 
 
{ 
 
    //useful vars 
 
    $new_line = "\n"; 
 

 
    //start building content 
 
    if($cycle == 1) { $output = 'xmlRequest='.$new_line; } 
 
    $output.= tabify($cycle - 1).'<'.$wrapper.'>'.$new_line; 
 
    foreach($arr as $key => $val) 
 
    { 
 
     if(!is_array($val)) 
 
     { 
 
      $output.= tabify($cycle).'<'.htmlspecialchars($key).'>'.$val.'</'.htmlspecialchars($key).'>'.$new_line; 
 
     } 
 
     else 
 
     { 
 
      $output.= print_r_xml($val,$key,$cycle + 1).$new_line; 
 
     } 
 
    } 
 
    $output.= tabify($cycle - 1).'</'.$wrapper.'>'; 
 

 
    //return the value 
 
    return $output; 
 
} 
 

 
/* tabify */ 
 
function tabify($num_tabs) 
 
{ 
 
    for($x = 1; $x <= $num_tabs; $x++) { $return.= "\t"; } 
 
    return $return; 
 
} 
 

 
$postStuff = array(
 
    'ReferralCode'=> 'ELE20590', 
 
    'PrimaryContact'=>array(
 
     'Email'=>'[email protected]', 
 
     'FirstName'=>'Test', 
 
     'LastName'=>'Test', 
 
     'HomePhone'=>'3035551234', 
 
    ), 
 
    'PickupAddress'=>array(
 
     'Address1'=>'410 17th St', 
 
     'City'=>'Denver', 
 
     'Zip'=>'80202' 
 
    ), 
 
    'MoveDetails'=>array(
 
     'PickupZip'=>'80202', 
 
     'DeliveryZip'=>'DeliveryZip', 
 
     'MoveDate'=>'5/1/2018', 
 
     'DwellingType'=>'10' 
 
    ), 
 
    'Comments'=>'blah blah blah' 
 
); 
 
echo print_r_xml($postStuff); 
 
$getPosts = print_r_xml($postStuff); 
 
$curl = curl_init(); 
 

 
curl_setopt_array($curl, array(
 
    CURLOPT_URL => "http://url-of-my-endpoint", 
 
    CURLOPT_RETURNTRANSFER => true, 
 
    CURLOPT_ENCODING => "", 
 
    CURLOPT_MAXREDIRS => 10, 
 
    CURLOPT_TIMEOUT => 30, 
 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
 
    CURLOPT_CUSTOMREQUEST => "POST", 
 
    CURLOPT_POSTFIELDS => $getPosts, 
 
    CURLOPT_HTTPHEADER => array(
 
    "content-type: application/x-www-form-urlencoded", 
 
), 
 
)); 
 

 
$response = curl_exec($curl); 
 
$err = curl_error($curl); 
 

 
curl_close($curl); 
 

 
if ($err) { 
 
    echo "cURL Error #:" . $err; 
 
} else { 
 
    echo $response; 
 
} 
 
?>

내가이 단지 그것을 XML 문자열을 공급 우체부에서 작동시킬 수 있습니다

여기 내 코드입니다. 그러나 이것이 과거의 방법을 알고 있다면 PHP입니다. 여기

내가 필요한 것보다 더 많은 필드 (모방하려고하는 것이, 작동 우체부 HTTP입니다 ...하지만 당신은 아이디어를 얻을.

POST /sirvaxmlfeed/requestanestimate.asmx/SendEstimateRequestXmlString HTTP/1.1 Host: ballpark.allied.com Content-Type: application/x-www-form-urlencoded Cache-Control: no-cache Postman-Token: 370cade0-fafd-63fb-dd8e-25af2dfd00ab xmlRequest= 
 
<EstimateRequest> 
 

 
    <ReferralCode>ELE20590</ReferralCode> 
 

 
    <PrimaryContact> 
 

 
    <Email>[email protected]</Email> 
 

 
    <FirstName>sample</FirstName> 
 

 
    <LastName>sample</LastName> 
 

 
    <PrimaryPhoneType>H</PrimaryPhoneType> 
 

 
    <PreferredContactTime>A</PreferredContactTime> 
 

 
    <HomePhone>3035551234</HomePhone> 
 

 
    <WorkPhone>2223334444</WorkPhone> 
 

 
    <WorkPhoneExt>112</WorkPhoneExt> 
 

 
    <CellPhone>2223334444</CellPhone> 
 

 
    <FaxPhone>2223334444</FaxPhone> 
 

 
    </PrimaryContact> 
 
    <PickupAddress> 
 

 
    <Address1>410 17th St</Address1> 
 

 
    <Address2></Address2> 
 

 
    <City>Denver</City> 
 

 
    <State>CO</State> 
 

 
    <Zip>80202</Zip> 
 

 
    </PickupAddress> 
 

 
    <MoveDetails> 
 

 
    <Process>True</Process> 
 

 
    <PickupZip>80202</PickupZip> 
 

 
    <DeliveryZip>80110</DeliveryZip> 
 

 
    <MoveDate>5/1/2018</MoveDate> 
 

 
    <DwellingType>A1</DwellingType> 
 

 
    <AmountOfFurnishings>M</AmountOfFurnishings> 
 

 
    <PickupShuttle>Y</PickupShuttle> 
 

 
    <DeliveryShuttle>N</DeliveryShuttle> 
 

 
    <AgentCode>2059000</AgentCode> 
 

 
    <CalendarTitle>Bob’s Appointment</CalendarTitle> 
 

 
    <CalendarLocation>West Wayne WASHINGTON, DC 20001 US</CalendarLocation> 
 

 
    <CalendarAppointmentDate>12/13/2017</CalendarAppointmentDate> 
 

 
    <CalendarAppointmentTime>09:00</CalendarAppointmentTime> 
 

 
    <CalendarAppointmentTimeOfDay>AM</CalendarAppointmentTimeOfDay> 
 

 
    <CalendarDuration>1 hour</CalendarDuration> 
 
    <CalendarUserName>[email protected]</CalendarUserName> 
 

 
    <CalendarSalesPersonId>12345</CalendarSalesPersonId> 
 

 
    <CalendarDetail>LMP Lead ID:1026861 Cust Name:Johny Test</CalendarDetail> 
 

 
    <CalendarURL> 
 
     <![CDATA[http://www.google.com/calendar/feeds/[email protected]/private/full/0qqbfbnjc7gr2hqa02ibua5irs]]> 
 
    </CalendarURL> 
 

 
    </MoveDetails> 
 

 
    <EstimateDetails> 
 

 
    <HasVehicles>Y</HasVehicles> 
 

 
    <RequestedEstimateDate>3D</RequestedEstimateDate> 
 

 
    <RequestedEstimateTimeOfDay>A</RequestedEstimateTimeOfDay> 
 

 
    <SpecialtyItems>sample text</SpecialtyItems> 
 

 
    <Comments>sample text</Comments> 
 

 
    <HTTPUserAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2)</HTTPUserAgent> 
 

 
    <VendorId>ABC123</VendorId> 
 

 
    <VendorName>ABCD</VendorName> 
 

 
    <VendorParms>aid=12345,sid=12345</VendorParms> 
 

 
    <OptInForSpecialOffers>Y</OptInForSpecialOffers> 
 

 
    <ThirdPartyOptIn>Y</ThirdPartyOptIn> 
 

 
    <VendorDateTime>11/19/2015 11:30:00</VendorDateTime> 
 

 
    <ReferrerFirstName>Jim</ReferrerFirstName> 
 

 
    <ReferrerLastName>George</ReferrerLastName> 
 

 
    <ReferrerEmail>[email protected]</ReferrerEmail> 
 

 
    <MortgageDetails> 
 

 
     <Process>True</Process> 
 

 
     <LoanType>P</LoanType> 
 

 
     <LoanAmount>300000</LoanAmount> 
 

 
     <DownPayment>10</DownPayment> 
 

 
     <CurrentInterestRate>5.25</CurrentInterestRate> 
 

 
     <MortgageState>IL</MortgageState> 
 

 
     <Comments> 
 
     <![CDATA[No comments]]> 
 
     </Comments> 
 

 
     <CreditProfile>E</CreditProfile> 
 

 
     <PreQualifiedForMortgage>Y</PreQualifiedForMortgage> 
 

 
     <OfferCode>abc</OfferCode> 
 

 
     <PreferredContactTime>M</PreferredContactTime> 
 

 
     <ExistingHomeBalance>200000</ExistingHomeBalance> 
 

 
    </MortgageDetails> 
 

 
    <RealEstateDetails> 
 

 
     <Process>True</Process> 
 

 
     <TransactionType>X</TransactionType> 
 

 
     <IsHomeListedForSale>Y</IsHomeListedForSale> 
 

 
     <ExpirationDate>08/30/2015</ExpirationDate> 
 

 
     <ApproximateSalePrice>285000</ApproximateSalePrice> 
 

 
     <IsPreQualified>Y</IsPreQualified> 
 

 
     <RealEstateState>IL</RealEstateState> 
 

 
     <Comments> 
 
     <![CDATA[No comments even now]]> 
 
     </Comments> 
 

 
    </RealEstateDetails> 
 

 
    <HomeValue> 
 

 
     <Process>True</Process> 
 

 
     <CurrentHomeValue>285000</CurrentHomeValue> 
 

 
     <NewHomeValue>330000</NewHomeValue> 
 

 
     <AgencyNumber>AI2345</AgencyNumber> 
 

 
     <SalesCode>SCP0079</SalesCode> 
 

 
     <SalespersonName>Sales123</SalespersonName> 
 

 
     <SalespersonEmail>[email protected]</SalespersonEmail> 
 

 
    </HomeValue> 
 
    </EstimateDetails> 
 
</EstimateRequest>

답변

-1

당신이 할 수있는 't은 이렇게 :

$_POST = array(
    'ReferralCode'=> 'ELE20590', 
    'PrimaryContact'=>array(
     'Email'=>'[email protected]', 
     'FirstName'=>'Test', 
     'LastName'=>'Test', 
     'HomePhone'=>'3035551234', 
    ), 
    'PickupAddress'=>array(
     'Address1'=>'410 17th St', 
     'City'=>'Denver', 
     'Zip'=>'80202' 
    ), 
    'MoveDetails'=>array(
     'PickupZip'=>'80202', 
     'DeliveryZip'=>'DeliveryZip', 
     'MoveDate'=>'5/1/2018', 
     'DwellingType'=>'10' 
    ), 
    'Comments'=>'blah blah blah' 
); 

$_POST는이 같은 변수로 설정할 수 없습니다하는 자동 전역입니다

을.

if에 $ output을 정의한 경우 $cycle != 1으로 설정하면이 섹션이 실패하므로 설정하지 않으면 추가 할 수 없습니다. 여기

if($cycle == 1) { 
    $output = 'xmlRequest='.$new_line; 
} 
$output.= tabify($cycle - 1).'<'.$wrapper.'>'.$new_line; 

같은 문제는, $return가 설정되지 않습니다

function tabify($num_tabs) { 
    for($x = 1; $x <= $num_tabs; $x++) { 
     $return.= "\t"; 
    } 
    return $return; 
} 
+0

좋아, 다른 변수 이름 등을 사용하여 내 원래의 코드를 업데이트 ...하지만 오류가 남아있다. – JoethaCoder

+0

나는 또한 원래 우편의 끝에 우편 배달부 http를 추가했습니다. – JoethaCoder

+0

업데이트 된 답변 – miknik

관련 문제