Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:45:06+00:00 2026-06-07T19:45:06+00:00

Microsoft’s own PHP example for new Bing API doesn’t work. I tried in many

  • 0

Microsoft’s own PHP example for new Bing API doesn’t work. I tried in many ways, it just shows:

Server Error
401 – Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page
using the credentials that you supplied.

Example Coding given in the official documentation is below, it breaks up at

'proxy' => 'tcp://127.0.0.1:8888',  

I am 100% sure my key is correct, and when I just enter it in the browser url it works fine, i.e

https://api.datamarket.azure.com/Bing/SearchWeb/Web?Query=%27love+message%27

(you need to put the API key as your password and username can be anything)

<html>
    <head>
        <link href="styles.css" rel="stylesheet" type="text/css" />
        <title>PHP Bing</title>
    </head>
    <body>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
            Type in a search:

            <input type="text" id="searchText" name="searchText"
                value="<?php
                        if (isset($_POST['searchText']))

                                   {
                            echo($_POST['searchText']);
                        }
                        else
                        {
                            echo('sushi');
                        }
                       ?>"
            />

            <input type="submit" value="Search!" name="submit" id="searchButton" />
            <?php
                if (isset($_POST['submit']))
                {
                    // Replace this value with your account key
                    $accountKey = 'BKqC2hIKr8foem2E1qiRvB5ttBQJK8objH8kZE/WJVs=';

                    $ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';

                    $WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';

                    $context = stream_context_create(array(
                        'http' => array(
                            //'proxy' => 'tcp://127.0.0.1:8888',
                            'request_fulluri' => true,
                            'header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
                        )
                    ));

                    $request = $WebSearchURL . urlencode( '\'' . $_POST["searchText"] . '\'');

                    echo($request);

                    $response = file_get_contents($request, 0, $context);

                    print_r($response);

                    $jsonobj = json_decode($response);

                    echo('<ul ID="resultList">');

                    foreach($jsonobj->d->results as $value)
                    {
                        echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');

                        echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>');
                    }

                    echo("</ul>");
                }
            ?>
        </form>
    </body>
</html>

I have tried both google API and Yahoo API both, none of those were as difficult as this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:45:08+00:00Added an answer on June 7, 2026 at 7:45 pm

    after days of argument with microsoft techinchal support they accpeted that it didnt work

    here is the proper coding which uses CURL do this in the BING API, apply CURL method instead of the file_get_contents which can’t pass the correct authentication information from Linux client to BING service.

    <html>
        <head>
            <title>PHP Bing</title>
        </head>
        <body>
            <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                Type in a search:
    
                <input type="text" id="searchText" name="searchText"
                    value="<?php
                            if (isset($_POST['searchText']))
    
                                       {
                                echo($_POST['searchText']);
                            }
                            else
                            {
                                echo('sushi');
                            }
                           ?>"
                />
    
                <input type="submit" value="Search!" name="submit" id="searchButton" />
                <?php
    
    
                    if (isset($_POST['submit']))
                    {
    
                $credentials = "username:xxx";
    
                    $url= "https://api.datamarket.azure.com/Bing/SearchWeb/Web?Query=%27{keyword}%27";        
                    $url=str_replace('{keyword}', urlencode($_POST["searchText"]), $url);
                    $ch = curl_init();
    
                $headers = array(
                        "Authorization: Basic " . base64_encode($credentials)
                    );
    
                    $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
                    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
                    curl_setopt($ch, CURLOPT_FAILONERROR, true);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
                    $rs = curl_exec($ch);
                echo($rs);
                    curl_close($ch);
                    return $rs;
    
            }
    
                ?>
            </form>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Microsoft's new Windows Live Application Based Storage API is a RESTful API. More info
Microsoft like implementing their own versions of popular open-source frameworks and assemblies, for example:
Microsoft introduced a new System.IO.MemoryMappedFiles namespace in .Net 4. Does anyone know if it
Microsoft Word has send as attachment functionality which creates a new message in Outlook
Microsoft recently released tools and documentation for its new Phone 7 platform, which to
Microsoft recently announced their Facebook SDK. http://msdn.microsoft.com/en-us/windows/ee388574.aspx Has anyone tried using it with ASP.NET
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = Document; // Default file name dlg.DefaultExt =
Microsoft claims that the .Net 3.5 framework has many speed improvements over 2.0. Is
Microsoft have recently released a Bing maps objective c component. See here and here
Microsoft (and many developers) claim that the SqlDataReader.GetOrdinal method improves the performance of retrieving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.