SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    curl ... Why wont this work?

    PHP Code:
    foreach ($form_fields as $key => $val){
        
    $curl_post_vars .= $key '=' urlencode($val) . '&' ;    
    }
    $curl_post_vars substr($curl_post_vars0,-1);

    //initialize curl post
        
    $ch curl_init($curl_post_url);
        
    $file fopen("output.txt""w");
         
    curl_setopt($chCURLOPT_POST      ,1);
         
    curl_setopt($chCURLOPT_VERBOSETRUE);

         
    curl_setopt($chCURLOPT_POSTFIELDS    ,$curl_post_vars);
         
    curl_setopt($chCURLOPT_FOLLOWLOCATION  0);
         
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);

         
    curl_setopt($chCURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
         
    curl_setopt($chCURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL

    curl_setopt($chCURLOPT_STDERR$file); 
        
    $curl_result curl_exec($ch);

        
    fclose($file);
        
    curl_close($ch);

    echo 
    $curl_result
    any ideas why this wont work?
    Attached Files Attached Files

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    How is it not working? What errors are you getting?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by laytone View Post
    PHP Code:
    foreach ($form_fields as $key => $val){
        
    $curl_post_vars .= $key '=' urlencode($val) . '&' ;    
    }
    $curl_post_vars substr($curl_post_vars0,-1);

    //initialize curl post
        
    $ch curl_init($curl_post_url);
        
    $file fopen("output.txt""w");
         
    curl_setopt($chCURLOPT_POST      ,1);
         
    curl_setopt($chCURLOPT_VERBOSETRUE);

         
    curl_setopt($chCURLOPT_POSTFIELDS    ,$curl_post_vars);
         
    curl_setopt($chCURLOPT_FOLLOWLOCATION  0);
         
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);

         
    curl_setopt($chCURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
         
    curl_setopt($chCURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL

    curl_setopt($chCURLOPT_STDERR$file); 
        
    $curl_result curl_exec($ch);

        
    fclose($file);
        
    curl_close($ch);

    echo 
    $curl_result
    any ideas why this wont work?
    Why don't you use:
    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'true); 
    sript at top of the page & note errors/warnings if any

  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added:

    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'true); 
    There are no errors and no data. All this page does is collects a form post, ads some variables to the array, builds a query string and posts it. It should return a simple xml success or error but its returning nothing. And if you look at the output.txt the remote server is just closing the connection?

    Am I not using curl correctly? Or am I forgetting a step?

  5. #5
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry

    I found out that curl is working by using:

    PHP Code:
    var_dump($curl_result); 
    string '
    Code XML:
    <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?><!DOCTYPE web_service>
     
    	<response>
     
    		<sale><![CDATA[ERROR]]></sale>
     
    		<error><![CDATA[Invalid Data In Fields: ccyear,ccmonth/ccyear]]></error>
     
    	</response>
    ' (length=219)

    but php will not echo the string contents to the screen. Why is this?


    HTML Code:
    <html>
    <head><title>test</title></head>
    <body>
    <p>Curl Result:<br>
    <?php echo $curl_result; ?>
    <br>Info:<br>
    <?php var_dump($curl_result); ?>
    </p>
    </body>
    </html>

  6. #6
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know what exactly the problem is.
    Can you explore some curl classes available @ user contributed notes in PHP manual & try that instead:
    http://php.net/curl

  7. #7
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code XML:
    <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?><!DOCTYPE web_service> 
        <response> 
            <sale><![CDATA[ERROR]]></sale> 
            <error><![CDATA[Invalid Data In Fields: ccyear,ccmonth/ccyear]]></error> 
        </response>
    XML is not HTML that is detected by browser for the proper display.

  8. #8
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHPycho View Post
    Code XML:
    <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?><!DOCTYPE web_service> 
        <response> 
            <sale><![CDATA[ERROR]]></sale> 
            <error><![CDATA[Invalid Data In Fields: ccyear,ccmonth/ccyear]]></error> 
        </response>
    XML is not HTML that is detected by browser for the proper display.
    That makes perfect sense.

    When I use <pre> tags around it I am getting just empty space too. I can highlight it but there are not characters. --??


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •