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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:15:09+00:00 2026-06-08T00:15:09+00:00

I’m attempting to implement a PHP method of authenticating a request to Associated Press

  • 0

I’m attempting to implement a PHP method of authenticating a request to Associated Press feeds. From their docs:

To authenticate all feed and content requests, the AP WebFeeds system uses HTTP Basic Authentication, which is currently the standard for syndicated feeds. Most feed readers and reader components allow the configuration of user credentials ahead of time and pass them in the headers rather than in the URL.

Important: Passing the credentials directly in the URL is currently widely blocked. For more information, see Microsoft’s security bulletin at http://www.microsoft.com/technet/security/bulletin/MS04-004.mspx.

You can configure a reader or component to create an authentication header with the name / value in the following format:

("Authorization", "Basic " + {Encoded_username_and_password})

where {Encoded_username_and_password} is replaced with the Base64 encoding of the bytes in the string “username:password.”

If you are writing your own client code to download a feed, use HTTP Basic Authentication that is built into your programming language’s library. HTTP Basic Authentication is available on most platforms; for example, Perl, PHP, C or Java.

My attempt is:

 /**
 * Begin Transaction
 */

$url = "http://syndication.ap.org/AP.Distro.Feed/GetFeed.aspx?idList=" . implode(',', $idList) . "&idListType=products&maxItems=25";    
$auth = "Authorization=Basic " . base64_encode($user . ":" . $pass);    
$ch = curl_init();  // initialize curl handle   
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to  
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable   
curl_setopt($ch, CURLOPT_POST, 1); // set POST method   
curl_setopt($ch, CURLOPT_POSTFIELDS, $auth); // add POST fields 
$result = curl_exec($ch); // run the whole process  
curl_close($ch);

/**
 * End Transaction
 */

var_dump($result);

Which gives me:

string(405) "

    Authentication
    FeedServer
    Authentication Failed on GetFeed

    Authentication denied no auth credentials detected

"

What’s the correct way to authenticate this request in PHP?

(See also the provided ASP.NET and Java examples)

  • 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-08T00:15:11+00:00Added an answer on June 8, 2026 at 12:15 am

    Authorization is an HTTP header not a POST parameter. You used CURLOPT_POSTFIELDS which sets the body of the request. Instead, you need to set it using CURLOPT_HTTPHEADER (The entry for it is pretty far down in the list):

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode($user . ":" . $pass)));
    

    And in case it wasn’t obvious already, you don’t need to make this as a post request (unless the API requires it), so you can remove:

    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.