cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2103
Views
0
Helpful
3
Replies

xml API problem with PHP

cate.derossi
Level 1
Level 1

Hi, I'm using xml API in php to insert a meeting in my application. I've taken the sample page available on the link

https://developer.cisco.com/site/webex-developer/develop-test/xml-api/sample-code/

unfortunately the result is always:

HTTP / 1.1 400 Bad Request

Date: Wed, 06 Sep 2017 07:25:38 GMT

Server: Apache

Content-Length: 28

Connection: close

Content-Type: text / html; charset = iso-8859-1

Http / 1.1 Service Unavailable

I think I have not realized which credentials are included in the webExID and password fields

I insert those with which I access my webwex site

mysite.webex.com

with which I also use the $ XML_SITE field

$XML_SITE="mysite.webex.com"

Can anyone help me to understand?

Thank you so much!

Angela

1 Accepted Solution

Accepted Solutions

ryanhunt
Level 5
Level 5

The sample code for PHP is faulty and no longer functional, it has a malformed header that is getting rejected (should have \r\n terminations and it does not).. here is a newer example that does not attempt to make its own HTTP Headers.

<?php

        header("Content-Type: text/xml");

        $sitename = "apidemoeu";        //Sitename is the subdomain of a WebEx URL. ex: sitename for https://apidemoeu.webex.com is apidemoeu

        $username = "username";

        $password = "password";

        $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

        $XML .="<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";

        $XML .="        <header>";

        $XML .="                <securityContext>";

        $XML .="                        <webExID>$username</webExID>";

        $XML .="                        <password>$password</password>";

        $XML .="                        <siteName>$sitename</siteName>";

        $XML .="                        <returnAdditionalInfo>TRUE</returnAdditionalInfo>";

        $XML .="                </securityContext>";

        $XML .="        </header>";

        $XML .="        <body>";

        $XML .="                <bodyContent xsi:type=\"java:com.webex.service.binding.site.GetSite\">";

        $XML .="                </bodyContent>";

        $XML .="        </body>";

        $XML .="</serv:message>";

        $request = stream_context_create(array("http"=>array("method"=>"POST","header"=>"Content-Type:text/xml","content"=>$XML)));

        $response = file_get_contents("https://$sitename.webex.com/WBXService/XMLService", false, $request);

        echo $response;

?>

View solution in original post

3 Replies 3

ryanhunt
Level 5
Level 5

The sample code for PHP is faulty and no longer functional, it has a malformed header that is getting rejected (should have \r\n terminations and it does not).. here is a newer example that does not attempt to make its own HTTP Headers.

<?php

        header("Content-Type: text/xml");

        $sitename = "apidemoeu";        //Sitename is the subdomain of a WebEx URL. ex: sitename for https://apidemoeu.webex.com is apidemoeu

        $username = "username";

        $password = "password";

        $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

        $XML .="<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";

        $XML .="        <header>";

        $XML .="                <securityContext>";

        $XML .="                        <webExID>$username</webExID>";

        $XML .="                        <password>$password</password>";

        $XML .="                        <siteName>$sitename</siteName>";

        $XML .="                        <returnAdditionalInfo>TRUE</returnAdditionalInfo>";

        $XML .="                </securityContext>";

        $XML .="        </header>";

        $XML .="        <body>";

        $XML .="                <bodyContent xsi:type=\"java:com.webex.service.binding.site.GetSite\">";

        $XML .="                </bodyContent>";

        $XML .="        </body>";

        $XML .="</serv:message>";

        $request = stream_context_create(array("http"=>array("method"=>"POST","header"=>"Content-Type:text/xml","content"=>$XML)));

        $response = file_get_contents("https://$sitename.webex.com/WBXService/XMLService", false, $request);

        echo $response;

?>

Hi Hunt,

Thank you for the reply. Unfortunately, this code also returns an error:

This page contains the following errors:

error on line 2 at column 1: Additional content at the end of the document

Below is the rendering of the page up to the first error.

I copied your code and modified only the sitename, username and password parameters....

I can not really understand why!

Hi Hunt,

in the weekend I tried and tried .... I was able to turn on the connection, so I no longer have the error.

I'm using the following code:

<html>

<head>

<title>Test XML API</title>

</head>

<body>

<?php

    $XML_PORT="443";

    //user information

    $UID = "myUserId"; // WebEx username

    $PWD = "myPassword"; // WebEx password

    $siteName= "MysiteName WebEx"; //  SiteName 

    

    // Build XML request document

    $d["XML"] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    $d["XML"] .= "<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchemainstance\"";

    $d["XML"] .= "xmlns:serv=\"http://www.webex.com/schemas/2002/06/service\"";

    $d["XML"] .= "xsi:schemaLocation=\"http://www.webex.com/schemas/2002/06/service";

    $d["XML"] .= "http://www.webex.com/schemas/2002/06/service/service.xsd\">";

    $d["XML"] .= " <header>";

    $d["XML"] .= " <securityContext>";

    $d["XML"] .= " <webExID>$UID</webExID>";

    $d["XML"] .= " <password>$PWD</password>";

    $d["XML"] .= " <siteName>$siteName</siteName>";

  $d["XML"] .= " <returnAdditionalInfo>TRUE</returnAdditionalInfo>";    

    $d["XML"] .= " </securityContext>";

    $d["XML"] .= " </header>";

    $d["XML"] .= "<body>"; 

    $d["XML"] .= "<bodyContent xsi:type=\"java:com.webex.service.binding.site.GetSite\">"; 

    $d["XML"] .= "</bodyContent>"; 

    $d["XML"] .= "</body>"; 

    $d["XML"] .= "</serv:message>";     

    $URL = "https://" . $siteName. ".webex.com/WBXService/XMLService";

    $Result = postIt($d,$URL,$XML_PORT);

    if (isset($Result["errno"]))

        { // Unable to connect to server

        $errno = $Result["errno"];

        $errstr = $Result["errstr"];

        echo "<hr><B>XML Server Connection Error: $errno </B>$errstr<hr>";

    }

    else

        { // Server connection made

        echo "<br><b>XML Response document</b>";

        // Output XML response document

    echo("<pre>");

   while (list($key, $val) = each($Result))

   {

       $transval=htmlspecialchars($val);

       echo $transval;

   }

    echo "</pre>";

    exit;

}

//

// postIt()

//

// POSTs the XML request document and calling user variables

// to the specified WebEx XML Server and receives

// an XML response document

//

function postIt($DataStream, $URL, $Port)

{

    // Strip http:// from the URL if present

    $URL = ereg_replace("^https://", "", $URL);

    // Separate into Host and URI

    $Host = substr($URL, 0, strpos($URL, "/"));

    $URI = strstr($URL, "/");

    // Form the request body

    $ReqBody = "";

    while (list($key, $val) = each($DataStream)) {

        if ($ReqBody) $ReqBody.= "&";

        $ReqBody.= $key."=".urlencode($val);

}

$ContentLength = strlen($ReqBody);

// Generate the request header

//"Content-Type: application/x-www-form-urlencoded\n".

$Request =

    "POST $URI HTTP/1.0\n".

    "Host: $Host\n".

    "User-Agent: PostIt\n".

    "Content-Type: application/xml\n".

    "Content-Length: $ContentLength\n\n".

    "$ReqBody\n";

// Open the connection to the XML Server

$socket = fsockopen($Host, $Port, &$errno, &$errstr);

if (!$socket) { // Server connection error

$Result["errno"] = $errno;

$Result["errstr"] = $errstr;

return $Result;

}

$idx = 0;

// Send XML request request

fputs($socket, $Request);

// Process XML response

while (!feof($socket) && $Result[$idx-1] != "0\r\n")

{

    if (substr($Result[$idx-1], 0, 2) == "0\r\n")

        echo "The End:".strlen($Result[$idx-1]);

    $Result[$idx++] = fgets($socket, 4096);

    }

    return $Result;

}

?>

</body>

</html>

The problem is that when I send the request the result is  a blank page, if I do the dump I see that the response array has only one element with a Bool= False value ...

array(1) { [0]=> bool(false) }

I think I do not have access to my webex site correctly.

Can you help me understand what's going on?