Jump to content

Requesting web page data using CURL


redbrad0

Recommended Posts

I have a sample PHP script where I am posting data to UPS using curl, and then getting the data returned. The problem I am having is when I get curl_exec to pull the data and store it in a variable, it is actually printing it out on the web page. Does someone see a problem with this script on why its pulling the data and printing it instead of storing in the $result variable?

 

 

$xmlRequest =  "<?xml version=\"1.0\"?>\n".
            "<AccessRequest>\n".
            "   <AccessLicenseNumber>" . $LicenseNumber . "</AccessLicenseNumber>\n".
            "   <UserId>" . $Username . "</UserId>\n".
            "   <Password>" . $Password . "</Password>\n".
            "</AccessRequest>\n".
            "<?xml version=\"1.0\"?>\n".
            "<AddressValidationRequest xml:lang=\"en-US\">\n".
            "   <Request>\n".
            "       <TransactionReference>\n".
            "           <CustomerContext>MarketingWebForce.com</CustomerContext>\n".
            "           <XpciVersion>1.0001</XpciVersion>\n".
            "       </TransactionReference>\n".
            "       <RequestAction>AV</RequestAction>\n".
            "   </Request>\n".
            "   <Address>\n";
$xmlRequest  .= "       <City>Oklahoma City</City>\n";
$xmlRequest .= "       <StateProvinceCode>OK</StateProvinceCode>\n";
$xmlRequest   .= "       <PostalCode>73142</PostalCode>\n";
$xmlRequest .= "   </Address>\n".
            "</AddressValidationRequest>";
                  
//set POST variables
$url = 'https://wwwcie.ups.com/ups.app/xml/AV';

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,'1');
curl_setopt($ch,CURLOPT_POSTFIELDS,$xmlRequest);

[color=red]//execute post
echo "<hr>PULLING DATA<br>";
$result = curl_exec($ch);
echo "<hr>DATA PULLED<br>";[/color]

//close connection
curl_close($ch);

echo "<hr>PRINTING DATA<br>";
print_r($result);
echo "<hr>DATA PRINTED<br>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.