I am porting a old project written in plain php to zend framework(and I am new to zend), I am using zend http client(with cURL adapter) in zend project to replace the cULR part of old php project. I got stuck-up as I don't know the zend http client alternate for
$landing_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
which return the url of the landing page after any redirection during the cURL request. I could able to be successfully do the following with zend
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
),
);
$redirecting_page_address ='https://www.domain.tld/someredirectingurl';
$client = new Zend_Http_Client($redirecting_page_address, $config);
$response = $client->request();
and got the required page as output using $response->getBody() now I want to know the url of the landed page where $redirecting_page_address redirected to. Thanks in advance.
As Cyril answered for himself, there is no high-level API in zend framework 2 (2.2.8 2014-09-17) to fetch the effective URL. You can, however, fetch the original curl handle and use native PHP functions on it:
// $client would be a Zend_Http_Client
$handle = $client->getAdapter()->getHandle();
$effectiveUrl = curl_getinfo($handle, CURLINFO_EFFECTIVE_URL);
If redirect is done by headers, you can use
if ($response->isRedirect()){
$newUrl = $response->getHeader('Location');
}
In my research over this I found there no way to do this till the current versions of zend framework (2.0.6), maybe in the future versions this facility can be included.
Related
I am building an application which will eventually reside on the same domain where another application resides; both of which are written in PHP. One is a Laravel application and the other a Magento 1.9 store.
To authenticate the user, the Laravel application requires that a certain cookie be set by the Magento store's response, subsequently retrieved and parsed, all before authentication may continue.
My current strategy is a POST to a custom controller which delivers multiple Set-Cookie headers from the Magento store.
The one I need is something like:
Set-Cookie: auth_token=TheValueWeNeedToContinueAuthenticating; domain='.mydomain'; ...
The server I am testing on is an in-house staging environment. The server's VHost is set to Laravel's public directory, as usual.
The Magento store is on a different server however the TLD is the same .mydomain
I have verified the response in Postman, I am indeed returning the cookie with the correct Set-Cookie in place, however it is not visible in my Laravel application as the other cookies from Magento, are. The other cookies were verified within the response as I dumped Guzzle's CookieJar and still received all but the cookie I am looking for.
I am using PHP's Guzzle HTTP Library to post from a Laravel 5.6 app using PHP 7.1
The Magento1.9 store unfortunately uses PHP/5.6.35
When I dump the HTTP response I am getting the cookies which would normally receive had I actually visited any page within the store.
What else could I check to ensure I am taking to right approach to receiving this cookie? Https is the transmission protocol, and the content-type is x-www-form-urlencoded if that will assist an answer in any way.
Thank you.
UPDATE 1.0 - I was able to get a clean error reading from the request being sent.
{"status":"error","message":"invalid request"}
Here is my Guzzle Post request
$jar = new \GuzzleHttp\Cookie\CookieJar;
// Logging my error output -- I can share this if I must
$debug_file = fopen('../storage/logs/debug.txt', 'a');
try {
$payload = 'Knock, knock';
$url = '/api/for/post';
$client = new Client([
'base_uri'=> 'https://mySubdomain.myDomain.com',
'debug' => $debug_file,
'cookies' => $jar,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
$request = new \GuzzleHttp\Psr7\Request('POST', $url, [], $payload);
$rsp = $client->send($request);
dd($rsp->getBody()->read(1024));
$response->getBody()->read(1024) returns the error message
I want to use drupal_http_request to upload a file to another REST API and then parse the result into JSON.
I am able to generate a "PHP client" for this in Postman but it doesn't work in Drupal. Here is what it looks like:
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://api.cloudmersive.com/virus/scan/file');
$request->setRequestMethod('POST');
$request->setHeaders(array(
'cache-control' => 'no-cache',
'apikey' => 'KEY_HERE'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
There are two issues - one, PostMan doesn't actually add the code to upload the file. Second, the above code won't run in Drupal because it is making references that aren't available so it looks like I need to use the drupal_http_request function. I'm having a hard time figuring out how to actually do that since I don't use PHP much.
Any thoughts on how I could actually post a file to that endpoint using only the built-in Drupal 7 functions, e.g. drupal_http_request?
I have been using an API for a WMS which has updated to include authentication headers. I have been provided some required details but have been unable to sucessfully use the API. I have asked the developers but they are unable to help as they do not use PHP.
Previous to the last update, this would work:
$wsdl = URL_HERE;
$soapClient = new SoapClient($wsdl);
$params = array('customer' => $get_users_company->custcode_code);
$response = $soapClient->GetProducts($params);
With the authentification headers, this is what I currently have which is causing the error Authentication header missing
$wsdl = URL_HERE;
$ns = NAMESPACE_HERE;
$soapClient = new SoapClient($wsdl);
$headerbody = array('ID' => 'PROVIDED_ID_HERE', 'KEY' => 'PROVIDED_KEY_HERE');
$headers = new SOAPHeader($ns, 'AuthHeader', $headerbody);
$soapClient->__setSoapHeaders($headers);
$response = $soapClient->__soapCall("GetProducts", array('customer' => $get_users_company->custcode_code));
I'm not 100% sure I am doing this correctly, but without the last line, I get no errors and the page loads fine (No results). Am I correct in thinking the headers are being sent?
I have heard the good old, "we can't help because we are XML Gods and your little php is beneath us"...but you can still get technical support from them by speaking their XML language. Dump out your actual, raw XML and communicate with them using that - don't mention PHP.
Follow the example here and get your request. Make sure it is matching what the documentation of your API is requesting. If it is, call your technical support and show them your XML. If it isn't, then, you know what you need to fix.
When using $soapClient->__soapCall() the second parameter takes an array, and your data structure is also an array, so you maybe should be doing:
$params = array('customer' => $get_users_company->custcode_code);
$response = $soapClient->__soapCall("GetProducts", array($params));
Or just leave it as:
$response = $soapClient->GetProducts($params);
Which looks nicer.
I'm trying to make a https request using zend framework 1.11, with http everithing is working fine, but when i change the request url to https://etc.com, I'm not more able to get the response.
i'm trying like a was reading in the manual like that:
$uri='https://url.com';
$adapter = new Zend_Http_Client_Adapter_Curl();
$client = new Zend_Http_Client();
$client->setUri($uri);
$client->setMethod('POST');
$client->setAdapter($adapter);
$adapter->setConfig(array(
'curloptions' => array(
CURLOPT_SSL_VERIFYPEER => false)
));
Log::notice("URL: " . $uri);
$response = $client->setRawData($xml, 'application/xml')->request('POST');
i activated already in my php.ini the php_curl.dll.
So only with https is not working, maybe somebody can tell me what i'm doing wrong.
Thanks.
Likely invalid certificate. If you can't change the server certificate to valid one, you have to set curl option to ignore invalid certificate:
$addapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
Usual stuff, Googled forever, looked on here, no help. Yet.
What I want is to list the sets of photos I have on Flickr. Nice & simple, it would seem.
I want the 'title image' (the one used as the thumb for it on Flickr its self), the title and URL. Can't be that hard, can it?
The language of choice is PHP (5.1.6), or JS (jQuery if possible). Both are good.
Using flickr.photos.search method of the API with your user_id does not work ?
For PHP, you have a PEAR-based package here and another library at http://phpflickr.com/. Should be enough to get through it.
EDIT :
For minimal implementation you should use stream_context_create() with HTTP headers, use fopen() with this context and build a XMLRPC request by hand as a text variable that you will send. Answer from the socket will be your data
For the API, use flickr.photosets.getList
CODE EXAMPLE (you need a valid api key for flickr)
<?php
$apiKey = '';
$userID = '';
$url = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key='
.$apiKey.'&user_id='.$userID.'&format=json';
$options = Array('http' => Array('method' => 'GET'));
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$object = json_decode($response);
see also http://framework.zend.com/manual/en/zend.service.flickr.html for a nice tidy wrapper