0

I have the following command that works perfectly on the command line,

curl -X POST --header 'Category: network;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";,virtualnetwork; scheme="http://schemas.opennebula.org/occi/infrastructure#";class="mixin";' --header 'X-OCCI-Attribute: occi.core.title="My Network",occi.core.summary="A short summary", opennebula.network.size=256, opennebula.network.address="192.168.0.0",opennebula.network.bridge=virbr0,opennebula.network.public=YES,opennebula.network.type=RANGED' http://localhost:4567/network/

I've tried to make the same request using cURL extension in php as follows:

    $ch = curl_init("http://localhost:4567/network/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
header('Content-type: text/plain; charset=utf-8');
curl_setopt($ch,CURLOPT_VERBOSE,true);  
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Category : network;scheme="http://schemas.ogf.org/occi/infrastructure#",class="kind"',
        'Category : virtualnetwork; scheme="http://schemas.opennebula.org/occi/infrastructure#";class="mixin"'));

curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-OCCI-Attribut : occi.core.title="Third Network"',
        'X-OCCI-Attribut : occi.core.summary="Test Net"', 
        'X-OCCI-Attribut : opennebula.network.size=256',
        'X-OCCI-Attribut : opennebula.network.address="10.10.10.0"',
        'X-OCCI-Attribut : opennebula.network.bridge=br0',
        'X-OCCI-Attribut : opennebula.network.public=YES',
        'X-OCCI-Attribut : opennebula.network.type=RANGED'
        ) );
 curl_setopt($ch, CURLOPT_POST, 1);
 $response = curl_exec($ch);

The request fails and nothing is added on the server.

I've tried also the HTTPRequest but still unable to make the request:

            $arg= array(
        'Category : network;scheme="http://schemas.ogf.org/occi/infrastructure#",class="kind"',
        'Category : virtualnetwork; scheme="http://schemas.opennebula.org/occi/infrastructure#";class="mixin"',
        'X-OCCI-Attribut : occi.core.title="Third Network"',
        'X-OCCI-Attribut : occi.core.summary="Test Net"', 
        'X-OCCI-Attribut : opennebula.network.size=256',
        'X-OCCI-Attribut : opennebula.network.address="10.10.10.0"',
        'X-OCCI-Attribut : opennebula.network.bridge=br0',
        'X-OCCI-Attribut : opennebula.network.public=YES',
        'X-OCCI-Attribut : opennebula.network.type=RANGED'
        ) ;

        $this->httpRequest->addPostFields($arg);

Any suggestions ??

I've added the following line according to this link:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); 

and got :

HTTP/1.1 400 Bad Request
Connection: close
Date: Fri, 29 Jul 2011 09:01:31 GMT
Content-Type: text/plain
Content-Length: 0
Server: OCCI/1.1

I've succeded, I needed just to correct the headers, and remove the

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); 

The correct header is :

    curl_setopt($ch, CURLOPT_HTTPHEADER,array('Category: network;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";,virtualnetwork; scheme="http://schemas.opennebula.org/occi/infrastructure#";class="mixin";',
        'X-OCCI-Attribute: occi.core.title="My Net",occi.core.summary="A netw summary", opennebula.network.size=256, opennebula.network.address="10.0.0.0",opennebula.network.bridge=virbr0,opennebula.network.public=YES,opennebula.network.type=RANGED')); 
 curl_setopt($ch, CURLOPT_POST, 1);
 $response = curl_exec($ch);
0

1 Answer 1

1

Use wireshark to debug network flow.

Sign up to request clarification or add additional context in comments.

5 Comments

GET and DELETE request are successful, so I suspect the request is wrong, no problem with the network
you can also look at the content which is being transfered. Do you notice a difference between curl command and curl extension?
That's a key, if you could help me figure out a way to "translate" curl commands to curl extension instructions
I don't know libCurl..I just wanted to give you an idea and a tool to approach your problem :) I suggest you download wireshark and look at the TCP content from curl then compare your TCP content from your curl extension. Then you see what's going on. Or you wait for someone who posts the correct answer :)
I'm using live http headers extension of firefox to monitor the communication, should be enough, no really need to analyse packets with wireshark, thx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.