function post_data($url, $xml_string)
{
    $url = $url;
    $theData = $xml_string;
    //
    $credentials = 'user@example.com:password';
    $header_array = array('Expect' => '', 'From' => 'User A');
    $options = array(headers => $header_array, httpauthtype => HTTP_AUTH_BASIC, protocol => HTTP_VERSION_1_1);
    //create the httprequest object
    $httpRequest_OBJ = new httpRequest($url, HTTP_METH_GET, $options);
    //add the content type
    $httpRequest_OBJ->setContentType = 'Content-Type: text/xml';
    //add the raw post data
    $httpRequest_OBJ->setBody($theData);
    //
    try {
        //send the http request
        $result = $httpRequest_OBJ->send()->getBody();
        $resp_code = $httpRequest_OBJ->getResponseCode();
        //print_r($result);
        if ($resp_code == 200) {
            return $result;
        }
        //return $result;
    } catch (HttpException $ex) {
        echo $error;
    }
}
Ejemplo n.º 2
0
<?php

$ind = 1;
foreach ($_POST as $key => $value) {
    $matrx[$key] = $value;
    $ind++;
}
$rparams = json_encode($matrx);
$url = 'http://127.0.0.1:8888';
$header_array = array('Content-Type' => 'application/json', 'Content-Length' => strlen($rparams), 'Transfer-encoding' => 'chunked');
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST);
$httpRequest_OBJ->setHeaders = $header_array;
$httpRequest_OBJ->setContentType = 'Content-Type: application/json';
$httpRequest_OBJ->setBody($rparams);
//send the http request
$result = $httpRequest_OBJ->send();
//print out the result
echo $httpRequest_OBJ->getResponseBody();