2017-02-17 7 views
0

これは初めてのことです。私は、http api経由でデータベースを検索し、結果をウェブサイトに表示する検索フォームを作成しようとしています。呼び出しは、許可が必要です。http apiで検索する検索フォームを作成

$headers = array ('headers' => array( 
        'Authorization' =>  'bearer' . $token , 
        'Content-type' =>  'application/json', 
        'Accept'  =>  'application/json')); 

マイ検索フォームは次のようになります。

<form method="GET" accept="application/json" action="https://example.xx/api/v1/products?page=1&size=5&direction=asc&search=value"> 
    <input type="text" name="search" size="40" maxlength="256" value="" placeholder="testsearch"> 
    <input type="submit" name="search_button" value="Search"> 
</form> 

私は入力フィールドに何かを入力して送信ボタンを押すと、ブラウザが表示されます。

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"} 

ブラウザのアドレス欄には、

https://example.xx/api/v1/products?search=testvalue&search_button=Search 

明らかに承認は無視され、URLは私が自分のウェブサイトを離れたことを示しています。

私はaction = "somephp.php"でこの作業をしなければなりませんか? フォームからの呼び出しを許可し、その回答をウェブサイトに表示するにはどうすればよいですか? ヒントが大変感謝しています。

<form method="post" id="api-result-searchform" action=""> 
    <input type="text" class="search" placeholder="<?php echo esc_attr_x('Author?', 'placeholder') ?>" value="" name="searchauthor" id="s" title="api-search" /> 
    <input class="button"type="submit" name="search_button" value="Search"> 
</form> 

そしてコール:

<?php 
    $searchterm = $_POST['searchauthor']; 
    $url = 'https://example.de/api/v1/product?search=ti=' . $searchterm; 
    $response = wp_remote_get($url, $headers); 
    //etc. 

これがうまく機能 フォーム - テオドイツWordPressのフォーラムに

答えて

0

おかげで、私は答えを見つけました。

関連する問題