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 8665291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:26:51+00:00 2026-06-12T17:26:51+00:00

When try to create a new API request with the Windows Azure new Bing

  • 0

When try to create a new API request with the Windows Azure new Bing based API, Using the code below

$url= 'https://'.$this->m_host.'/Web?Query={keyword}&Adult=%27Off%27&$top=50&$format=Atom';     

        $url=str_replace('{keyword}', urlencode($this->m_keywords), $url);

        // Replace this value with your account key
                    $accountKey = $this->key;

                    $WebSearchURL = $url;

                    $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;
                    $response = file_get_contents($request, 0, $context);

        print_r($response);

i get following error.

Warning: file_get_contents() [function.file-get-contents]: 
Couldn't connect to server in /home/xxxxx on line 43

Warning: file_get_contents(https://api.datamarket.azure.com/ 
failed to open stream: operation failed in /home/xxxx/ bing_search.php on line 43

Any idea why this fails ? or is it best to use the CURL Library than the file_get_contents() ?

  • 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-12T17:26:52+00:00Added an answer on June 12, 2026 at 5:26 pm

    The below code works for me, it is to search news but it will work for web searches too.

    Just replace appkey with your one, leave username as it is (i.e. username) since it is ignored by the server

    function getBingResult($keyword)
    {
        $credentials = "username:appkey";
        $url= "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/News?Query=%27{keyword}%27". "&\$format=json";        
        $url=str_replace('{keyword}', urlencode($keyword), $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);
        curl_setopt($session, CURLOPT_VERBOSE, TRUE); 
    
        $rs = curl_exec($ch);
        $jsonobj = json_decode($rs);
        curl_close($ch);    
        return $jsonobj;
    }
    

    Testing the function:

    $bingResult = getBingResult("John");
    foreach($bingResult->d->results as $value)
    {   
        echo '<pre>'."URL:". $value->Url.'</pre>';
        echo '<pre>'."Title:". $value->Title.'</pre>';
        echo '<pre>'."Description:". $value->Description.'</pre>';   
        echo '<pre>'."Source:". $value->Source.'</pre>';   
        echo '<pre>'."Date:". $value->Date.'</pre>';   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to create a new file inside a JSP and try to save
I'm try to create a new list object. I set the new object to
Whenever I try to edit existing or create new distribution provisioning profile on iOS
Im try to create a spinner dynamically on press of a button. this is
Using iOS 5's new TWRequest API, I've ran into a brick wall related with
Using the TFS API, I am able to create a TFS item, no problem.
Hi i want to create an uploading video program using youtube api I think
Similar to this forum post: https://developer.citrixonline.com/forum/request-not-expected-format However he didn't really explain what he found
I'm using the Twilio API to send broadcast SMS messages based on an approved
I'm new to MVC but I'm trying to create an MVC Web API and

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.