Empty Result Curl in php - php

I'm having a problem with PHP's cURL returning an empty string with some URL's
i want to coonect this api and i give the empty result, anyone can help me ?
<?php
$clTrid="TEST-23233434343";
$nictoken="6661361102210630";
$contact="Test-irnic";
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<contact:info xmlns:contact="http://epp.nic.ir/ns/contact-1.0">
<contact:id>' . $contact . '</contact:id>
<contact:pw>' . $nictoken . '</contact:pw>
</contact:authInfo>
</contact:check>
</check>
<clTRID>' . $clTrid . '</clTRID>
</command>
</epp>';
$url = 'https://epp.nic.ir/submit';
$curl = curl_init($url);
curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
else echo " No Error ! ";
if(curl_errno($curl)){
throw new Exception(curl_error($curl));
}
curl_close($curl);
echo $result;
var_dump($result);
?>

Related

(Close) PHP with SOAP, server to get xml from request

I'am new hand about soap
I've a client.php code witch send a xml to server.php.
How to read xml to array in my server.php?
I always get the value without the key
Do I using wsdl to parse xml?
But I'm not good at wsdl...
Can someone help me? Thx a lot.
client.php
<?php
$data = '<?xml version = "1.0" encoding = "UTF-8"?>
<inputMessage>
<ns0:BankCollStatusAdviseRq xmlns:ns0 = "http://ns.tcb.com.tw/XSD/TCB/BC/Message/BankCollStatusAdviseRq/01">
<ns0:SeqNo>00000000</ns0:SeqNo>
<ns0:TxnCode>ARROWAPAN095912 </ns0:TxnCode>
<ns0:CollInfo>
<ns0:CollId>006</ns0:CollId>
<ns0:CurAmt>
<ns0:Amt>1000</ns0:Amt>
</ns0:CurAmt>
</ns0:CollInfo>
<ns0:SettlementInfo>
<ns0:SettlementId>0063201924</ns0:SettlementId>
</ns0:SettlementInfo>
</ns0:BankCollStatusAdviseRq>
<headers>
<Header.PartyInfo>
<ns0:PartyInfo xmlns:ns0 = "http://www.tibco.com/namespaces/bc/2002/04/partyinfo.xsd">
<from>
<name>BANK006</name>
</from>
<operationID>BankColl/1.0/BankCollStatusAdvise</operationID>
</ns0:PartyInfo>
</Header.PartyInfo>
</headers>
<ns0:_configData xmlns:ns0 = "http://tibco.com/namespaces/tnt/plugins/soap">
<endpointURL>https://dev.admin.roombook.com.tw/automsgclient_tc.php?wsdl</endpointURL>
<soapAction>/BankColl</soapAction>
</ns0:_configData>
</inputMessage>';
$url = "http://localhost:8080/test/soap/demo2/server.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/soap+xml",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
server.php
<?php
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
exit;
}
$postData = trim(file_get_contents('php://input'));
echo "<pre>";print_r($postData);echo "</pre>";
libxml_use_internal_errors(true);
$xml = simplexml_load_string($postData);
if($xml === false) {
header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Request", true, 400);
foreach(libxml_get_errors() as $xmlError) {
echo $xmlError->message . "\n";
}
exit;
}
?>

Sending XML fails

I'm trying to send XML to a remote site. I originally coded it using curl. That failed (no response) and the rep for the company said it was because I was using curl. So I changed the code to not use it but it fails with
file_get_contents(https://testws.atdconnect.com/ws/3_4/locations.wsdl/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
The code I am using is shown below. The first call tries to send with curl while the second doesn't. Can someone point out where I am going wrong, please?
$client_id = "the id";
$username = "the user";
$password = "the pass";
$url = "https://testws.atdconnect.com/ws/3_4/locations.wsdl/";
echo GetDistributionCenter($url, $client_id, $username, $password);
echo GetDistributionCenter($url, $client_id, $username, $password, true);
function GetDistributionCenter($url, $client_id, $username, $password, $send_array = false) {
$xml_str = '
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://api.atdconnect.com/atd/3_4/locations">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken atd:clientId="' . $client_id . '" xmlns:atd="http://api.atdconnect.com/atd">
<wsse:Username>' . $username . '</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $password . '</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<loc:getDistributionCenterRequest>
<loc:servicingDC>070</loc:servicingDC>
</loc:getDistributionCenterRequest>
</soapenv:Body>
</soapenv:Envelope>';
if ($send_array) {
$xml_str = array($xml_str);
$xml_str = http_build_query($xml_str);
return SendPostRequest($url, $xml_str);
}
return SendXMLCommand($url, $xml_str);
}
function SendPostRequest($url, $postdata) {
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($postdata) . "\r\n",
'content' => $postdata
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
}
function SendXMLCommand($url, $parsed_data) {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt ($ch, CURLOPT_POSTFIELDS, $parsed_data);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data)));
$result = curl_exec($ch);
if (curl_error($ch)) {
$result = 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
return $result;
}

Embed XML in JSON POST to PHP-CURL

I have a requirement to post a REST call in the following JSON formt. Note the payload variable is XML. I'm using PHP 5 with CURL. Looking for what I'm doing wrong. Thanks
{
"processDefId":"testing~SimpleApplication!1.0~SimpleProcess",
"serviceName":"SimpleProcess.service",
"operation":"start",
"payload":"<payload><formArg><p0:WebForm1 xmlns:p0=\"http://www.frevvo.com/schemas/_N5J6IBUOEeWgf4K8GSSanA\"/></formArg></payload>",
"action":"Submit"
}
Constructed the following but am not getting a response nor seeing anything actioned on the called application.
try {
echo '<br>Curl Start<br>';
echo file_put_contents($log, "Start \n", FILE_APPEND);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"http://192.168.56.151:7003/bpm/api/3.0/processes");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_FAILONERROR);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json') );
curl_setopt($curl, CURLOPT_USERPWD, "jstein:welcome1");
$xml = '<ns1:start xmlns:ns1=\http://xmlns.oracle.com/bpm/webform/formsData/requestTravelAccount\">';
$xml .= '<formArg xmlns:ns2=\"http://www.frevvo.com/schemas/_1g73gMt3EeWsKsy3N_19_Q\">';
$xml .= '<ns2:RequestTravelAccount>';
$xml .= '<EmployeeId>1771</EmployeeId>';
$xml .= '<FirstName>Aaron</FirstName>';
$xml .= '<LastName>Thompson</LastName>';
$xml .= '<PersonId>300000087953021</PersonId>';
$xml .= '</ns2:RequestTravelAccount>';
$xml .= '</formArg>';
$xml .= '</ns1:start>';
$xml_e = htmlspecialchars($xml, ENT_QUOTES);
echo file_put_contents($log, $xml_e ."\n", FILE_APPEND);
$post_data = array(
"processDefId"=>"testing~HCM!1.0~NewEmployeeTravelSetupProcess",
"serviceName"=>"NewEmployeeTravelSetupProcess.service",
"operation"=>"start",
"action"=>"Submit",
"payload" => $xml_e
);
$curl_post_data = json_encode($post_data);
echo file_put_contents($log, "$curl_post_data"."\n", FILE_APPEND);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
echo '<br> CURL_EXEC return: ' . curl_error($curl);
} catch (Exception $e) {
echo 'Caught exception" ',$e->getMessage(), "\n";
}
curl_close($curl);
echo '<br>CURL done';
You are initializing the CURLOPT_HTTPHEADER option twice. Whereas you need to initialize it only once with all headers.
Wrong:
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json') ); // resetting above one for this line.
Correct:
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json') );

"type Invalid 16-bit integer. invalid Input.format.short " error while HTTP POST request using CURL

I am newbie with Social Minor I am trying to create a new Feed in Social Miner using "Social-Miner Create Feed API".
Problem:
When I click on "Create Feed" button on my interface I receive following error: " type Invalid 16-bit integer. invalid Input.format.short "
Code:
<?php
error_reporting(o);
$URL = "http://192.168.200.163:8080/ccp-webapp/ccp/feed";
//Create Feed form values
$type = $_POST['type'];
$feed_name = $_POST['feed_name'];
$description = $_POST['description'];
$ur = $_POST['ur'];
$polling_interval = $_POST['polling_interval'];
$minimum_age = $_POST['minimum_age'];
$reply_template = $_POST['reply_template'];
$tags = $_POST['tags'];
//Storing above values in a string
$myFeedString='<?xml version="1.0" encoding="utf-8"?>
<Feed>
<type>$type</type>
<name>$feed_name</name>
<description>$description</description>
<ur>$ur</ur>
<polling_interval>$polling_interval</polling_interval>
<minimum_age>$minimum_age</minimum_age>
<tags>
<tag>$tags</tag>
</tags>
</Feed>
';
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_USERPWD, "hashmatkhan" . ":" . "Army2life");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $myFeedString);
if (curl_errno($ch))
{
//moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
}
?>
Need Help?

SOAP request not returning a response

I am making a request to a search directory that looks up HIV specialists. Here is the documentation they provide: http://mobile.aahivm.org/getinfo.asmx?op=GetProviders
I use PHP's cUrl to make the request. Any idea why nothing is being returned?
<?php
$curlData = '<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetProviders xmlns="http://localhost">
<fname></fname>
<lname></lname>
<locationzip></locationzip>
<locationcity></locationcity>
<locationstate>New York</locationstate>
<locationcountry></locationcountry>
<primaryservicesid></primaryservicesid>
<credentials></credentials>
<specialty></specialty>
<specialtycare></specialtycare>
<support></support>
<paymentoptions></paymentoptions>
<member></member>
</GetProviders>
</soap12:Body>
</soap12:Envelope>';
$url='http://mobile.aahivm.org/getinfo.asmx?op=GetProviders';
$curl = curl_init();
$length = strlen($curlData);
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'POST /getinfo.asmx HTTP/1.1',
'Host: mobile.aahivm.org',
'Content-Type: application/soap+xml; charset=utf-8',
'Content-Length:'=>$length,
'SOAPAction: "http://localhost/GetProviders"'
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
//$result = substr(curl_exec($curl), 285, -72); ///remove SOAP envelope!
$result = curl_exec($curl);
print_r("Curl result: ".$result."<br><br><hr>");
curl_close ($curl);
$arr2 = array();
$arr2[] = json_decode($result, true);
////
foreach ($arr2 as $key=>$value) {
//echo $value;
$next[] = $value;
foreach ($next as $key=>$value) {
//echo $value;
$next[] = $value;
foreach ($next as $key=>$value) {
echo $key."=".$value."<br />";
}
echo "--<br /><br />";
}
}
/////
?>
Are you looking to retrieve all of the providers in the response?
In their documentation (http://mobile.aahivm.org/getinfo.asmx?op=GetProviders) it says " The placeholders shown need to be replaced with actual values." So im assuming you will need to send with your request, some sort of values for it to search for.
Hope this helps a bit

Categories