Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82938

how to send requests to the php libraries from php scripts

$
0
0
Hello,

I'm trying to send php based requests to a data source based on the Editor Php Libraries.

Can't understand where my requests fail.

Example:

Datasource Code:

<?php
 
/*
 * Example PHP implementation used for the index.html example
 */
 
// DataTables PHP library
include( "../lib/DataTables.php" );
 
// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Validate;
 
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 's3storage' )
    ->fields(
        Field::inst( 'bucket' ),
        Field::inst( 'folder' ),
        Field::inst( 'name' ),
        Field::inst( 'size' ),
		Field::inst( 'creation_date' ),
		Field::inst( 'region' ),
		Field::inst( 'uploaded_by' ),
		Field::inst( 'hash' ),
		Field::inst( 'download_link' ),
		Field::inst( 'thumbnail_link' )
    )
    ->process( $_POST )
    ->json();
?>

Requester code:
<?php

$riga = array(
	"bucket" => "a",
	"folder" => "a",
	"name" => "a",
	"size" => "a",
	"region" => "a",
	"uploaded_by" => "a",
	"hash" => "a",
	"download_link" => "a",
	"thumbnail_link" => "a",
);


$request = array(
	"id" => -1,
	"table" => "",
	"action" => "create",
	"data" => $riga
);


$url = "./json_sources/ds_storages3.php";

        $content = json_encode($request);

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER,
                array("Content-type: application/json"));
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

        $json_response = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ( $status != 201 ) {
		  echo $response = json_decode($json_response, true);
            die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
        }


        curl_close($curl);

        $response = json_decode($json_response, true);
		echo $response;

?>

When I run the "requester script" this is the response I get:

[code[
ArrayError: call to URL http://www.rdev.it/dev/build/json_sources/ds_storages3.php failed with status 200, response {"id":-1,"error":"","fieldErrors":[],"data":[],"aaData":[]}, curl_error , curl_errno 0
[/code]

I've also tried to dump the POST request:

[Wed Jan 30 18:20:52 2013] [debug] mod_dumpio.c(74): mod_dumpio:  dumpio_in (data-HEAP): {"id":-1,"table":"s3storage","action":"create","data":{"bucket":"a","folder":"a","name":"a","size":"a","region":"a","uploaded_by":"a","hash":"a","download_link":"a","thumbnail_link":"a"}}

I really can not understand the reason that makes the request fail:

- the data format?
- the data contents?
- the http request?

Viewing all articles
Browse latest Browse all 82938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>