Skip to content

Instantly share code, notes, and snippets.

@SirPilgrims
Created July 4, 2014 13:10
Show Gist options
  • Save SirPilgrims/655379045c66690d1edb to your computer and use it in GitHub Desktop.
Save SirPilgrims/655379045c66690d1edb to your computer and use it in GitHub Desktop.
cURL php
#!/usr/bin/php
<?php
$proxy_login='user:psw';
$proxy_ip='000.000.000.000';
$proxy_port=8080;
$controller_login='user:psw';
$dataFlow='{
"installInHw":"true",
"name":"Flow1",
"node": {
"id":"00:00:00:00:00:00:00:00",
"type":"OF"},
"ingressPort":"2",
"etherType":"0x800",
"protocol":"6",
"tpDst":"80",
"priority":"65535",
"actions":["DROP"]}';
echo $dataFlow;
$url='http://000.000.000.000:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:00/staticFlow/Flow1';
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_login);
curl_setopt($ch, CURLOPT_USERPWD, $controller_login);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataFlow);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
if (!$result)
return false;
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment