refr3sh Posted February 26, 2015 Share Posted February 26, 2015 hello guys! i'm trying to convert this curl command line to php libcurl curl -X POST https://test.stellar.org:9002 -d ' { "method": "account_currencies", "params": [ { "account": "gM4Fpv2QuHY4knJsQyYGKEHFGw3eMBwc1U" } ] }' What I've done so far: <?php $method = "account_currencies"; $params = Array("account" => "gM4Fpv2QuHY4knJsQyYGKEHFGw3eMBwc1U"); $request = xmlrpc_encode_request($method, $params); $ch = curl_init(); $headers[] = "Content-Type: text/xml" ; $headers[] = "Content-length: ".strlen($request) . "\r\n"; $headers[] = $request; curl_setopt($ch, CURLOPT_URL, "https://test.stellar.org"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PORT , 9002); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); $response = curl_exec($ch); curl_close($ch); echo $response; ?> It should give me back a xml response but I just get: "Unable to parse request" Can anyone tell me whats wrong with the code? Quote Link to comment Share on other sites More sharing options...
boompa Posted February 26, 2015 Share Posted February 26, 2015 I'm not sure why you're trying to use XML, as the API docs indicate you should be using JSON. Something like this: <?php $request = array( 'method' => "account_currencies", 'params' => array('account' => "gM4Fpv2QuHY4knJsQyYGKEHFGw3eMBwc1U") ); $ch = curl_init(); $headers[] = "Content-Type: application/json"; $headers[] = "Content-length: ".strlen($request) . "\r\n"; curl_setopt($ch, CURLOPT_URL, "https://test.stellar.org"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PORT , 9002); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); $response = curl_exec($ch); curl_close($ch); echo $response; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.