2017-11-13 5 views
0

2日後に辞任しました。ブラウザのmagento2 apiからすべての製品のリストを取得したい。最初に "http://mydomain.con/index.php/rest/V1/products?Authorization=Bearer_TOKENHERE?searchCriteria="を試しましたが、動作しませんでした(まだ認証されていません)。ブラウザでMagento APIコールレスポンスを取得する方法

<?php 
 
//test for 1 product 
 
//API URL for authentication 
 
$apiURL="http://mydomain.con/index.php/rest/V1/integration/admin/token"; 
 

 
//parameters passing with URL 
 
$data = array("username" => "test", "password" => "123456qwe"); 
 
$data_string = json_encode($data); 
 

 
$ch = curl_init($apiURL); 
 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string))); 
 
$token = curl_exec($ch); 
 

 
//decoding generated token and saving it in a variable 
 
$token=json_decode($token); 
 

 
//******************************************// 
 

 
//Using above token into header 
 
$headers = array("Authorization: Bearer ".$token); 
 

 
//API URL to get all Magento 2 modules 
 
$requestUrl='http://mydomain.con/index.php/rest/V1/products/24-MB01'; 
 

 
$ch = curl_init($requestUrl); 
 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 
$result = curl_exec($ch); 
 

 
//decoding result 
 
$result=json_decode($result); 
 

 
//printing result 
 

 
print_r($requestUrl); 
 

 
print_r($result); 
 

 
?>

残念ながら、この呼び出しは私にPHPの嵐(ID、名前、SKU、価格の端末で完璧な答えを得る:私が試した次のことは、PHPのカールとのAPIを呼び出すことでした、などjsonで)しかし、私はエラー404リクエストURLは、サーバーで見つからない(ファイルが実際にアップロードされたとき)私はブラウザで答えを取得したい場合。

答えて

1

ウェブサーバーのどこかに問題があります。ドキュメントルートの.htaccessとapacheのホスト設定を確認してください。

+0

しかし、私が探しているものは何ですか? – Brunhilda

+0

サーバ上のファイルパス、ドキュメントルート、ホストconfig&.htaccessの内容などの詳細を指定します。それはいくつかのタイプミスまたは書き換えのルールかもしれません –

+0

私はそれはこの問題があるかもしれないと思う、すべてのmagento2.1プロジェクトはgitlabから私のサーバーにuplodedされているいくつかの基本的な構成は、これは奇妙なことですが、このサーバーにドメインを持っている私の仲間は同じコードでブラウザでapiを取得できます:/ – Brunhilda

関連する問題