PowerShell webservice query - web-services

There is PS script for verifying webservice and it works:
$SiteURL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP"
$request = [Net.HttpWebRequest]::Create($SiteURL)
try
{
#Get the response from the requst
$response = [Net.HttpWebResponse]$request.GetResponse()
Write-Host "The service is running."
$request.Abort()
}
Catch
{
Write-Warning "The service of site does not run or maybe you don't have the Credential"
}
But how I can specify query parameter, ZIP?

add a $zip parameter to get zip as an input
param($zip)
update your url to include zip when sending request
$siteURL="http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=$zip"

Related

Not Sure If Session Is Initiated Using Facebook PHP SDK

I'm trying to use Facebook's PHP SDK. The code that makes a call to Facebook to retrieve user's information is saved in a file called fbcall.php. The fbcall.php page is called through an href link from another page called index.php
The Entire Code (index.php):
<?php
echo "Login Here";
?>
Index.php is also my FacebookRedirectLoginHelper redirect url.
The question I have is that I'm not seeing an output for the following statement in the fbcall.php file and I'm not sure why?
echo "Name: " . $user_profile->getName();
I get the sense that my sessions isn't initiated but I'm sure how to validate this. And if it isn't initiated then I'm not sure what i'm doing wrong considering I'm following Facebook's guidelines here (or atleast I think I am).
The Entire Code (fbcall.php):
<?php
session_start();
// Make sure to load the Facebook SDK for PHP via composer or manually
require_once 'autoload.php';
//require 'functions.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// add other classes you plan to use, e.g.:
// use Facebook\FacebookRequest;
// use Facebook\GraphUser;
// use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('AM USING MY APP ID HERE','AM USING MY SECRET KEY HERE');
$helper = new FacebookRedirectLoginHelper('http://localhost/facebook/index.php');
$params = array('email','public_profile', 'user_status', 'user_friends');
$loginUrl = $helper->getLoginUrl($params);
try {
$session = $helper->getSessionFromRedirect();
// var_dump($session);
} catch(FacebookRequestException $ex) {
} catch(\Exception $ex) {
}
if (isset($session)) {
var_dump($session);
}
else
{
$loginUrl = $helper->getLoginUrl();
header("location:".$loginUrl);
exit;
}
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject();
if(isset($session)) {
try {
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className());
echo "Name: " . $user_profile->getName();
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
?>
Once the user grant your permissions, he/she will be redirected to index.php (because of your redirect_uri).
So there is two solutions:
- change you're redirect_uri to be fbcall.php
- move all fbcall.php logic to index.php, and change header("location:".$loginUrl); by echo "Login Here";

Pear SoapClient and Webservice Issue

I am trying to do a simple soap call to a weather service and I keep getting Invalid ZIP error. Can someone tell me what I am doing wrong below is my code.
Thanks
require_once 'SOAP/Client.php';
$client = new Soap_Client('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL');
$method = 'GetCityWeatherByZIP';
$params = array('ZIP' => '07108');
$result = $client->call($method, $params);
if (PEAR::isError($result)) {
echo $result->getMessage();
} else {
print_r($result);
}
Use PHP's in-built SOAP client. The one in PEAR was written at a time PHP did not have one itself.
Their service is no SOAP service. The wiki states:
$url = "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP";
$url .= "?ZIP=" . $this->ZipCode;
$this->response = simplexml_load_file($url) or die("ERROR");

Box API newbie connection problems

I'm trying to connect to the box-api to read the files of my user in my folder. I've created the folder and uploaded the files, then i went to the OAuth2 interface to obtain an API Key. It has given the api key to me so i pasted it in the code:
public function indexAction()
{
try {
$uri = "https://api.box.com/2.0/folders/0/items?limit=100&offset=0";
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER=>array("Authorization: Bearer MYKEY"),
CURLOPT_SSL_VERIFYPEER, false,
CURLOPT_USERPWD, "user:password"),
);
$client = new Zend_Http_Client($uri, $config);
$response = $client->request();
$text= $response->getBody();
} catch (Zend_Exception $e) {
echo "Message: " . $e->getMessage() . "\n";
// Other code to recover from the error
}
}
Following this tutorial on youtube.
The error i'm getting is the following:
Message: Error in cURL request: unable to use client certificate (no key found or wrong pass phrase?)
I registered the application with the name "test". What have I done wrong? What am I missing?
You might try passing the request without the CURLOPT_SSL_VERIFYPEER and CURLOPT_USERPWD options. I don't think those are strictly necessary -- to my knowledge Box doesn't do any client certificate validation -- and they may be causing the problem.
The use of Zend http client by itself is better than using the curl adapter.Besides the username and password are not required to authenticate. You can perform the operation only after you have received th access token from the authorization procedure of Oauth2 of Box-API. The zend http client call that can be used is the following:
$client = new Zend_Http_Client('https://api.box.com/2.0/folders/0');
$client->setMethod(Zend_Http_Client::GET);
$client->setHeaders('Authorization: Bearer '.$access_token);
$response = $client->request()->getBody();
My 2 cents.

SugarCRM - how to populate some field with web service response?

I have my index.php file which is calling web service out of sugar and it returns me as response when I run it on my local Apache this result which is OK:
<soapenv:Envelope <soapenv:Body> <ns:CommandResponseData>
<ns:Operation name="BalanceAdjustment"> </ns:Operation>
</ns:CommandResponseData> </soapenv:Body> </soapenv:Envelope>
I created one additional button within Detail View which I plan to call this web service but I do not know how to bind that button, my index.php file and result from that web service to pack in some field.
For testing purposes I would like to put this whole response on example in field Comment of Contact module: so that field Comment should Contain above whole response (I will later parse it).
I created new button (which does not do anything currently )
I created button in view.detail.php.
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/json_config.php');
require_once('include/MVC/View/views/view.detail.php');
class ContactsViewDetail extends ViewDetail
{
function ContactsViewDetail()
{
parent::ViewDetail();
}
function display()
{
$this->dv->defs['templateMeta']['form']['buttons'][101] = array (
'customCode' => '<input title="Call" accesskey="{$APP.LBL_PRINT_PDF_BUTTON_KEY}" class="button" onClick="javascript:CustomFunctionHere();" name="tckpdf" value="Call" type="button">');
parent::display();
}
}
?>
I will appreciate help with this. So to recapitulate : With this my button I want to call my index.php file which will call web service and I want to set web service response in my field Comment (I am getting response in index.php file as htmlspecialchars($client->__getLastResponse())
this is the whole index.php file that I am using currently to call some web service.
<?php
include_once 'CommandRequestData.php';
include_once 'CommandResponseData.php';
$client = new SoapClient("http://127.0.0.1:8181/TisService?WSDL", array(
"trace" => 1, // enable trace to view what is happening
"exceptions" => 1, // disable exceptions
"cache_wsdl" => 0) // disable any caching on the wsdl, encase you alter the wsdl server
);
$req = new CommandRequestData();
$req->Environment->Parameter[0]->name = "ApplicationDomain";
$req->Environment->Parameter[0]->value = "CAO_LDM_00";
$req->Environment->Parameter[1]->name = "DefaultOperationNamespace";
$req->Environment->Parameter[1]->value = "CA";
$req->Command->Operation->namespace = "CA";
$req->Command->Operation->name = "BalanceAdjustment";
$req->Command->Operation->ParameterList->StringParameter[0]->name = "CustomerId";
$req->Command->Operation->ParameterList->StringParameter[0]->_ = "387671100009";
$req->Command->Operation->ParameterList->IntParameter[0]->name = "AmountOfUnits";
$req->Command->Operation->ParameterList->IntParameter[0]->_ = "1000";
$req->Command->Operation->ParameterList->IntParameter[1]->name = "ChargeCode";
$req->Command->Operation->ParameterList->IntParameter[1]->_ = "120400119";
try {
$result = $client->ExecuteCommand($req);
$result->CommandResult->OperationResult->Operation->name . "<br /><br />";
}
catch(SoapFault $e){
echo "<br /><br />SoapFault: " . $e . "<br /><br />";
}
catch(Exception $e){
}
echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
?>

client send json and retrieve it in server

Now I'm bulding game by UNITY3D. I want to send json file to server to store it in database I build server by php with Yii Framework, i have problem with send data in client [UNITY3D] and retrieve it in server [Yii]. Please help me.UNITY3D code: I want to send 'name' -> to server
var url = "http://localhost:8888/TPP/index.php/site/saveName";
var form = new WWWForm();
form.AddField( "player", "Henry" );
var download = new WWW( url, form );
print(download);
yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
// show the highscores
Debug.Log(download.text);
}
In Yii, i tried to get data in request
public function actionSaveName() {
if(isset($_POST['name']) {
echo $_POST['name'];
} else {
echo "nothing";
}
}
Is that right?
The unity part is fine, but in yii you'll have to check for $_POST['player'] instead of $_POST['name'] because according to the AddField() documentation, the first parameter is the name of the generated form element.
If you want to have it as name then you'll have to change AddField as : form.AddField("name", "Henry");