1

I am new to php and need to query an oracle database using their API. I can send queries only as xml or json in the body. I am not sure if I am doing it right. Please find the code

<?php
    //HTTP Headers
    $header = array('Content-Type = application/xml','Accept = application/xml');
    $xmlquery =  <<<XML
    ---- query----
    XML;
    $body = simplexml_load_string($xmlquery);
    //URL containing query parameters : appGUID, pagenumber, pagesize 
    $url='http://<server name>?appGUID=<GUID>&pagenumber=1&pagesize=50';
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
    //CURLOPT_POSTFIELDS : The full data to post in a HTTP "POST" operation.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    var_dump ($response);
    curl_close($ch);
    ?>
hakre
  • 193,403
  • 52
  • 435
  • 836
  • See [this question](http://stackoverflow.com/questions/871431/raw-post-using-curl-in-php). You don't need `simplexml` at all, just post the xml string. – DCoder Sep 19 '12 at 11:37
  • You have forgotten to add the actual warning message to your question. Also `$body` is a simplexml object, `CURLOPT_POSTFIELDS` expects an array or string, please read the documentation for that option: http://php.net/manual/en/function.curl-setopt.php – hakre Sep 22 '12 at 15:58
  • Also please add some reference / documentation about endpoint you query here with curl. That looks like some webservice, not like a oracle database. E.g. please provide the link to the documentation. – hakre Sep 22 '12 at 15:59

1 Answers1

0

Simplexml_load_string returns an object containing the properties of your xml string. Curl_post expects your payload not an object. You should be able to post your XML string directly.

w01k3
  • 101
  • 1
  • 5
  • Thanks, i tried that but it still gives me, HTTP Status 415 - Cannot consume content type – user1682788 Sep 19 '12 at 12:06
  • This is what their documentation says : URL, Method : POST, HTTP Headers:“Content-Type” = “application/xml”OR“application/json” “Accept” = “application/xml” OR “application/json” , Query Parameters: appGUID, pagenumber, pagesize , Request Body :Search Criteria (XML/JSON) , Result: (XML/JSON) – user1682788 Sep 19 '12 at 12:18