I had exactly the same headache earlier this week. I found there are two
things to look out for:

For this line: curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str) - is
$post_str an array or a string? Both are acceptable, but if an array then
curl with automatically set the header "Content-Type: multipart/form-data".
This is what turned out to be the issue in my case.

The other thing is the Expect header. Not all servers like this, so try the
following to prevent it: curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Expect:'));

If all else fails, try replicating the headers that your browser would be
sending. This includes headers such as USER_AGENT and REFERER.

HTH.

Nathan.


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Brendan Brink
Sent: Friday, 20 August 2010 4:58 p.m.
To: [email protected]
Subject: [phpug] CURL issue

hi there,

any CURL experts out there?

I use CURL successfully in PHP for processing external pages and
havent had any issues before.

However today have the following issue:

This the URL i am trying to get info from through CURL:

http://121.98.150.62:5574/Invoice?txtcode=R5W2

When you go to this URL directly, works fine and displays the XML.

However, when I try and address this URL through CURL as follows, I do
not capture a response.

PHP CODE BELOW

                $ch = curl_init();
                        
                        curl_setopt($ch, CURLOPT_URL,
"http://121.98.150.62:5574/Invoice?txtcode=R5W2"; );
                        curl_setopt($ch, CURLOPT_POST, TRUE);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                        $xmlresponse = curl_exec($ch );
                        echo $xmlresponse; //this displays nothing and an
error when trying
to import the XML
                        //extract xml
                        
                         $dom = new domDocument;
                         $dom->loadXML($xmlresponse);
                         if (!$dom) {
                                echo 'Error while parsing the document';
                                
                                $returninfo['status'] = 0;
                                return $returninfo;
                                
                         }

                         $s = simplexml_import_dom($dom);



Greatly appreciate anyones help - sorry for a late Friday email!

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to