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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:47:42+00:00 2026-05-16T15:47:42+00:00

I am in a situation where I cannot use PHP cURL module to POST

  • 0

I am in a situation where I cannot use PHP cURL module to POST my form data. I have found a great blog post showing how to POST without using cURL here:
HTTP POST from PHP, without cURL

Here’s my problem though. When I attempt to send my POST request, the request hits the (other) server but the content (POST data) is not transmitted. The other server does not get the content. HOWEVER, if I do use cURL, it works fine. What am I missing? How can I recreate the cURL HTTP POST request without using cURL?

Here is the cURL code that works ($this->params is just $_POST which contains the form data):

$ch = curl_init($this->url);

$params = http_build_query($this->params);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL

$result = curl_exec($ch);
curl_close($ch);

return $result;

And here is my non-cURL version that does not work:

$postStr = http_build_query($this->params);

$opts = array(
    'http'=>array(
        'method' => $method,
        //'header' => 'Content-type: application/x-www-form-urlencoded',
        //'header' => 'content-type: multipart/form-data',
        'content-type' => 'application/x-www-form-urlencoded',
        'content-encoding' => 'UTF-8',
        'content' => $postStr
    )
);

$context = stream_context_create($opts);

$result = file_get_contents($this->url, false, $context);

return $result;

There are no errors or warnings. Just, the accepting server doesn’t appear to the contents. Any ideas?

  • 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-16T15:47:43+00:00Added an answer on May 16, 2026 at 3:47 pm

    It is likely your $method is not populated with 'POST'. The other major reason would have been an open_basedir restriction, but that would have generated a warning.

    Try explicitly naming “POST”

    $opts = array(
        'http'=>array(
            'method' => 'POST',
            'content-type' => 'application/x-www-form-urlencoded',
            'content-encoding' => 'UTF-8',
            'content' => $postStr
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation is simple: I post a plain HTML form with a textarea. Then, in
I have the following situation... I use CallableStatement from java.sql package. When I use
I use PHP, MySQL and Zend Framework. I have some simple tables with simple
I'm in a situation where I cannot use a vector because I use &element[x]
Situation: I have a page with an iframe, which contains a form. But the
ok here is the situation , I want to use a login form for
So I have 3 classes in this situation. Connection.php Engineer.php Status.php Both Engineer and
Situation: I have an index page which loads pages into it with ajax as
Situation: I have some persons with certain skills and they can/might belong to more
Situation is you have to develop an application against an Active Directory Tree. Want

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.