Author

Topic: [CLOSED] Bounty 5 BTC - Acessing CampBX API with PHP (Read 3184 times)

legendary
Activity: 1498
Merit: 1000
Received donation thank you and good luck with that asp migration
sr. member
Activity: 295
Merit: 250
Thanks for the donation, CA - I'll keep it away from satoshidice I think Smiley I do a fair bit of dev work on Windows Server and then deploy to a Linux box, so I'll keep an eye out for this one in future...

Now just got to figure out why php on osx hates anything https.

Saint Jobs needs to spy on you. He can't spy on your through https Tongue

Pretty sure the big bearded dude in the sky could pull a MITM attack if he wanted to. Does God have root?
donator
Activity: 305
Merit: 250
Cool dude.  Thanks for your help!
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Yeah, I agree.  Linux is a good system and much better for running PHP.  I have a few thousand lines of code in classic asp so the migration has been happening slowly but surely. 

Thanks again for everybody's help.  The bounty and most of the donations have been sent.  BCB, I got a 2BTC donation coming your way if you're interested (I don't see an address in your sig).

I appreciate that but I didn't solve the problem.  Happy to help you out.

Put the 2BTC towards a new linux box! Wink

Thanks!
donator
Activity: 305
Merit: 250
Yeah, I agree.  Linux is a good system and much better for running PHP.  I have a few thousand lines of code in classic asp so the migration has been happening slowly but surely. 

Thanks again for everybody's help.  The bounty and most of the donations have been sent.  BCB, I got a 2BTC donation coming your way if you're interested (I don't see an address in your sig).
member
Activity: 98
Merit: 10
(:firstbits => "1mantis")
Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  

Awesome - my 'tweak stuff til it does something different' approach works again... PM'd.

Now just got to figure out why php on osx hates anything https.

Saint Jobs needs to spy on you. He can't spy on your through https Tongue
sr. member
Activity: 295
Merit: 250
Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  

Awesome - my 'tweak stuff til it does something different' approach works again... PM'd.

Now just got to figure out why php on osx hates anything https.
member
Activity: 98
Merit: 10
(:firstbits => "1mantis")
PHP on IIS? UGH! No wonder!

DOOD! Switch to Linux for ANYTHING OPEN SOURCE!
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Ahhhh.  MS Server requires the Certificate. Linux does not.  Good to know. It makes me think that Campbx is also hosted on an MS Server box as you said you could authenticate to the other exchanges but not to Campbx.  Glad you got it working!
hero member
Activity: 504
Merit: 500
1MEYHC9c5gmJ4TPWCoFWW9Ey1TGLUjfMKi

Glad you got it worked out
donator
Activity: 305
Merit: 250
Does curl_error() give you anything? http://php.net/manual/en/function.curl-error.php

Nope, no errors.

Quote

Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  

If verifyhost set as 1, then also need the line to point to the certificate, but here is a working code.

Code:
$params['user'] = "myUser";
$params['pass'] = "myPass";
$postData = http_build_query($params, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://CampBX.com/api/myfunds.php");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_CAINFO, "path to certificate.crt");
//curl_setopt($ch,CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($ch, CURLOPT_SSLVERSION,3); // or try setting to 2  //This did the trick

$res = curl_exec($ch);
print_r($res);
echo 'Curl error: ' . curl_error($ch);
curl_close($ch);


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  
member
Activity: 98
Merit: 10
(:firstbits => "1mantis")
Code:
sudo apt-get install ruby1.9.1

Solved!

19nUeM1qJmkpr8KYf9frtfWj6MCX7jpjb
legendary
Activity: 924
Merit: 1004
Firstbits: 1pirata
Watching thread, and the skills some of you show off in here.
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Code:
curl_setopt($curl,CURLOPT_POST, true);

you forgot this so it will send as a post

Gweedo,

That is redundant when you are already calling

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

Try it.
sr. member
Activity: 295
Merit: 250
Does curl_error() give you anything? http://php.net/manual/en/function.curl-error.php

Looking at the curl_setopt() page has some things you could try (http://php.net/manual/en/function.curl-setopt.php):

Try using basic auth with:

Code:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );


Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2

The manual page says CURLOPT_SSL_VERIFYHOST can be either 1 or 2 with 2 being the default, so try 1 (instead of 0):

Code:
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);

Otherwise maybe it's something to do with encodings being used - see the CURLOPT_ENCODING option. If there's a way to show the headers you're sending, you could try comparing what you're sending across different machines, and if one works, what difference in headers there are.
donator
Activity: 305
Merit: 250
Thanks for the suggestion, but still getting a 404 bad request error with the code below.

Code:
$params['user'] = "myUser";
$params['pass'] = "myPass";

$postData = http_build_query($params, '', '&');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://CampBX.com/api/myfunds.php");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
//with or without:  curl_setopt($ch, CURLOPT_CAINFO, "path/cacert.crt");

$res = curl_exec($ch);
print_r($res);
curl_close($ch);
hero member
Activity: 504
Merit: 500
What about

$params['user'] = "username";
$params['pass'] = "password";

$postData = http_build_query($params, '', '&');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://CampBX.com/api/myfunds.php");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");


$res = curl_exec($ch);
print_r($res);
curl_close($ch);

?
donator
Activity: 305
Merit: 250
Thanks for the replies.  I will do some testing in the next couple of days and report back the results.  Thanks.

EDIT:  Still no go.  I verified that I am running php 5.3.9, curl 7.21.7 with openssl 0.9.8r.  I tried adding the cert and it didn't solve the problem.  I also tried running BCB's code on Ubuntu 11.10, Apache 2.0, PHP 5.3.6, curl 7.21.6, openssl 1.0.0e.  I think something is not set correctly and the CampBX server is still rejecting my requests with the bad request error.  I don't see any errors in the Apache error log either.  I am going to try contacting CampBX again to see if they can find anything in their logs.
full member
Activity: 126
Merit: 100
I'm no expert, but here are my suggestions:

First, make sure that you have OpenSSL installed. http://www.webhostingtalk.com/showthread.php?t=929949

Second, check to see if there are any proxy settings that aren't getting carried through. http://forums.iis.net/p/1173290/1973896.aspx#1973896

Third, try implementing the headers and curl options from the last post here: http://bytes.com/topic/php/answers/734722-getting-php-login-somewhere-post-username-password-then-get-cookies

BCB
vip
Activity: 1078
Merit: 1002
BCJ
CA Coins,

The code i posted works fine with my credentials on a CentOS server.  I think it an MS Server issue.  Have you contacted Keyur directly.  He's been very helpful with my requests. When you do find a solution please post.

Thanks.
legendary
Activity: 1498
Merit: 1000
Code:
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BTChash; '.php_uname('s').'; PHP/'.phpversion().')');

add this to your code, i looked at his source and this how he gets it to work
donator
Activity: 305
Merit: 250
Thanks for the link, but his library doesn't work for me for some reason.
legendary
Activity: 1498
Merit: 1000
https://bitbucket.org/brandonbeasley/campbx-php/overview
the have a library

also you may need to do basic auth to use curl
donator
Activity: 305
Merit: 250
I am surprised nobody has working code for accessing CampBX API with PHP.  Maybe it is just my setup?  Either way, I am going to throw in a 5 BTC bounty to whoever helps me solve this problem.  Please post or PM me.  Thanks.
donator
Activity: 305
Merit: 250
I am actually running this on win server 2008.  I don't see anything in the PHP error log or the IIS error log.  I can access the other exchanges (mtgox, bitfloor, intersango) with no issues.  Weird it is just with CampBX.
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Any output in your apache error_log?
donator
Activity: 305
Merit: 250
Yeah, I have been granted API access.  Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc.  But if I try to post the same data with cURL, I get
"Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request."

my cURL parameters:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://CampBX.com/api/myfunds.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);

if I use file_get_contents, I just get a blank page.



Try:

 $params['user'] = "username";
 $params['pass'] = "password";

 $postData = http_build_query($params, '', '&');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://CampBX.com/api/myfunds.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);

Thanks for your help, but I got the same response.  "Bad request..."
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Yeah, I have been granted API access.  Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc.  But if I try to post the same data with cURL, I get
"Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request."

my cURL parameters:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://CampBX.com/api/myfunds.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);

if I use file_get_contents, I just get a blank page.



Try:

 $params['user'] = "username";
 $params['pass'] = "password";

 $postData = http_build_query($params, '', '&');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://CampBX.com/api/myfunds.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);
donator
Activity: 305
Merit: 250
Yeah, I have been granted API access.  Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc.  But if I try to post the same data with cURL, I get
"Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request."

my cURL parameters:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://CampBX.com/api/myfunds.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);

if I use file_get_contents, I just get a blank page.
BCB
vip
Activity: 1078
Merit: 1002
BCJ
Have you requested api credentials access?  You have the request access.  There is no on and off in the user interface.  Then you can use your existing credentials.
donator
Activity: 305
Merit: 250
Does anybody have working code for connecting to the CampBX API with PHP?  I can get market data and account data if I post the auth info through a form, but I can't seem to connect to account data with cURL or file_get_contents in PHP.  The linked PHP library by Brandon Beasley also doesn't work for me for some reason.  Can't get a response from their support either for the last 2 weeks.  If anybody has working code to get account info via cURL or file_get_contents in PHP, I would much appreciate it.  Thanks.

EDIT:  Added 5 BTC bounty for whoever helps me solve this problem.  Thanks.
Jump to: