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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:58:56+00:00 2026-05-14T06:58:56+00:00

My code is using file_get_contents() to make GET requests to an API endpoint. It

  • 0

My code is using file_get_contents() to make GET requests to an API endpoint. It looks like it is using HTTP/1.0 and my sysadmin says I need to use HTTP/1.1. How can I make an HTTP/1.1 request? Do I need to use curl or is there a better/easier way?

Update

I decided to use cURL since I am using PHP 5.1.6. I ended up forcing HTTP/1.1 by doing this:

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

If I was using 5.3 or later I would have tried doing something like this:

$ctx = stream_context_create(array(
    'http' => array('timeout' => 5, 'protocol_version' => 1.1)
    ));
$res = file_get_contents($url, 0, $ctx);
echo $res;

http://us.php.net/manual/en/context.http.php

Note: PHP prior to 5.3.0 does not
implement chunked transfer decoding.
If this value is set to 1.1 it is your
responsibility to be 1.1 compliant.

Another option I found which might provide HTTP/1.1 is to use the HTTP extension

  • 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-05-14T06:58:56+00:00Added an answer on May 14, 2026 at 6:58 am

    I’d use cURL in either case, it gives you more control and in particular it gives you the timeout option. That’s very important when calling an external API so as not to allow your application to freeze whenever a remote API is down.

    Could like this:

    # Connect to the Web API using cURL.
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, 'http://www.url.com/api.php?123=456'); 
    curl_setopt($ch, CURLOPT_TIMEOUT, '3'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $xmlstr = curl_exec($ch); 
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    curl_close($ch);
    

    cURL will use HTTP/1.1 per default, unless you specify something else using curl_setopt($s,CURLOPT_HTTPHEADER,$headers);, where $headers is an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the IndentingXMLStreamWriter-Class to get a well formatted XML-file. The code looks
When using PHP I can use file_get_contents or cURL to get a URL. jQuery
I'm using ASIHTTPRequest API to get some JSON data from a web side. I'm
I am using the below PHP code with Google's Translate API and I have
How can I make a post request using cookies from php. My php code:
I'm using Jinja2's nl2br filter, which looks like: import re from jinja2 import environmentfilter,
I am using the Twilio REST API to make reminder calls and I'm not
I start a download using PHP with this code: <? $_REQUEST['file'] = urldecode($_GET['file']); header(Content-type:
i am generating *.reg file using code which will have some important data. and
I tried this aproach without any success the code I'm using: // File name

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.