Jump to content

Need help with cURL


SharkBait

Recommended Posts

Ok I have an weird issue and I am trying to figure out why it is working on my development server at home and not my live server.

 

DevServer:

PHP Version 5.2.3

cURL Version: 7.16.4

 

curl_getinfo($ch):

[url] => http://twitter.com/direct_messages/new.xml
    [content_type] => application/xml; charset=utf-8
    [http_code] => 200
    [header_size] => 717
    [request_size] => 260
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.199514
    [namelookup_time] => 0.050506
    [connect_time] => 0.086238
    [pretransfer_time] => 0.086274
    [size_upload] => 0
    [size_download] => 1286
    [speed_download] => 6445
    [speed_upload] => 0
    [download_content_length] => 1286
    [upload_content_length] => 0
    [starttransfer_time] => 0.19862
    [redirect_time] => 0

 

Live Server:

PHP Version 5.2.6

cURL VersioN: 7.18.2

 

curl_getinfo($ch):

[url] => http://twitter.com/direct_messages/new.xml
    [content_type] => application/xml; charset=utf-8
    [http_code] => 200
    [header_size] => 717
    [request_size] => 260
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.199514
    [namelookup_time] => 0.050506
    [connect_time] => 0.086238
    [pretransfer_time] => 0.086274
    [size_upload] => 0
    [size_download] => 1286
    [speed_download] => 6445
    [speed_upload] => 0
    [download_content_length] => 1286
    [upload_content_length] => 0
    [starttransfer_time] => 0.19862
    [redirect_time] => 0

 

This is the script:

<?php
$text = 'This is a lot of fun right?';

$ch = curl_init('http://twitter.com/direct_messages/new.xml');

$userpwd = "{$username}:{$password}";

$data = 'user=' . $target . '&text=' . urlencode($text);

curl_setopt($ch, CURLOPT_USERPWD, $userpwd); 
curl_setopt ($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_NOBODY, 0); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_USERAGENT, $twit_plugin_name .' '. $twit_plugin_ver);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch); 
?>

 

According to the live server it is not getting any POST information and I am not sure why.  Is there an option in php.ini or something that might be forcing PHP cURL to use GET and not POST?

 

Now I have set data as a STRING and as an ARRAY and both return the same error message on my Live Server.

 

What am I missing? What other things can I look for?

 

 

Link to comment
Share on other sites

Things that could be your problem (but most likely not):

 

1)Seems strange to be HTTP posting to an .xml file. Sure this is correct?

 

2)You don't have definitions for a few of the variables, but I assume they are defined earlier in your script?

 

3)Are all the parameters necessary? Try it with just the userpwd, post, and postfields...

 

My solution:

Try forming an HTTP request with fsockopen and sending headers with fwrite/fputs instead of cURL.

Link to comment
Share on other sites

i was following Twitter's API with HTTP to an XML file.

 

But with more investigation it might be an issue with a newer version of the libcURL which I think has issues with sending data after being redirected in the case of say load balancing.

 

I tried the script on 3 servers in total. The live server has a newer version of the libcURL whereas the 2 other servers are back a few revisions.

 

But I will try using an fsockopen and seeing what i get. Thanks for the suggestion!

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.