Jump to content

WebService not working properly


Sgarbo

Recommended Posts

Hello! I've a problem with prestashop 1.7.6.5

On a server, there are two prestashop sites (different websites, not multistore)


One to the public_html/b2b directory - Prestashop 1.6.1.12


One to the public_html/store directory - Prestashop 1.7.6.5

 

it would be www.website.com/b2b and www.website.com/store

Two separate databases also.

I want to add photos to products via webservice. I've a php script for this. 

//image will be associated with product id 4
        $url = "http://www.website.com/b2b/api/images/products/$id_product";

        $ch = curl_init();
        //$cfile = array('image'=>"@".$img_path.";type=image/jpeg");

        #$args['file'] = new CurlFile($img_path);

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        //curl_setopt($ch, CURLOPT_PUT, true);
        curl_setopt($ch, CURLOPT_USERPWD, pr_API_KEY.':');
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('image'=> new CurlFile($img_path)));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $result_curl = curl_exec($ch);
        $errors = curl_error($ch);
        $response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if($result_curl === false)
          echo "Error $url: $errors\n<br>";
        elseif ($response != 200)
          echo "Error response http $url: $response\n<br>";
        else
          echo "Done: {$api}images/products/$id_product<br />\n<br />\n";

        curl_close($ch);

It, as suggested by prestashop, use the string http: //[email protected]/b2b/api
It works perfectly.

On the second site (PS 1.7.6.5)  instead, if I do the same thing http: //[email protected]/store/api I am redirected to the homepage. Even If I try to writing only  http://mysite.com/store/api I am redirected to homepage....

Could anyone help me understand why? 

Edited by Sgarbo (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Do you have Webservice enabled? (Advanced settings -> Webservice -> Activate webservice)

Have you tried giving the key as GET-parameter? (http://mysite.com/store/api?ws_key=xxx)

Link to comment
Share on other sites

Il 1/6/2020 alle 12:47, roombausato disse:

il problema della chiave sbagliata deriva dal fatto
che i servizi Web Prestashop non consentono l'autenticazione
se il PHP in esecuzione sul server è impostato in modalità PHP-FPM a
causa di un bug Prestashop che verifica l'autenticazione
attraverso una variabile di sistema non disponibile in questa configurazione.

PHP-FPM è il modo più performante / recente di eseguire PHP
sul server ed è attivo di default su tutto il nostro hosting ottimizzato
(Https://bobcares.com/blog/php-fpm-advantages/).

Il problema è stato anche evidenziato e discusso dal team Prestashop:
https://github.com/PrestaShop/PrestaShop/issues/15385
ma non è mai stato gestito.

Esistono 3 soluzioni:

1)
Aggiungi queste due righe nella parte superiore del file .htaccess alla radice del sito:

RewriteEngine su
RewriteRule. * - [E = HTTP_AUTHORIZATION:% {HTTP: Autorizzazione}]

2)
Notifica a coloro che utilizzano il servizio web di richiamarlo
passando la chiave di autenticazione come parametro GET ws_key nell'URL
e non come autenticazione http / base

Esempio di una chiamata funzionante: http://sitoweb.com/api?ws_key=xxxxxxxxxxxxxx

3)
Chiedici di disabilitare il supporto PHP-FPM e impostarlo su PHP-CGI
(questo rallenterà le prestazioni complessive).


L'ho risolto aggiungendo questo in .htaccess
RewriteEngine su
RewriteRule. * - [E = HTTP_AUTHORIZATION:% {HTTP: Autorizzazione}]

 

 

Edited by roombausato (see edit history)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...