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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:15+00:00 2026-05-26T23:22:15+00:00

If I make a POST request where the content-type is not set in the

  • 0

If I make a POST request where the content-type is not set in the request header, the variable $_POST remains empty.

Question: How can I force PHP to fill $_POST?

I encountered the problem making an Javascript AJAX request using XDomainRequest where you can not define any headers. Just to make it easier for you to understand the problem you can simulate the same effect without Javascript in PHP this way:

$data = 'test=1';

$fp = fsockopen('www.yourpage.org', 80, $errno, $errstr, 5);
fputs($fp, "POST /test_out.php HTTP/1.1\r\n");
fputs($fp, "Host: www.yourpage.org\r\n");
//fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);

while(!feof($fp)) { echo fgets($fp, 128); }
fclose($fp);

test_out.php would be

var_dump($_POST);

Without the correct content-type the variables in $_POST magically disappear.

This is more an educational question. I am asking this because most people here can not imaging that the content-type has this effect. I was asked to ‘come back with facts’. So here you go.

  • 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-26T23:22:16+00:00Added an answer on May 26, 2026 at 11:22 pm

    You can override/inject the necessary header using Apache mod_headers if you have to. Or otherwise resort to manually reconstructing the $_POST array. (See also userland multipart/form-data handler)

    If it’s always urlencoded, simply read from php://input (Which contains the raw POST request body) and use parse_str:

    parse_str(file_get_contents("php://input"), $_POST);
    

    That should recreate the POST array, pretty much like PHP would do.

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

Sidebar

Related Questions

My OCSP client is sending me the following HTTP request: POST <NULL> HTTP/1.0 Content-Type:
Is it possible to make a POST request from Ruby with open-uri?
I'd like to have one server make an http post request to another server.
I'm working at an app which would make a POST ajax request to a
Is there a way to get the Content-Type of the response or conversely set
My task is simple: make a post request to translate.google.com and get the translation.
I want to receive the following HTTP request in PHP: Content-type: multipart/form-data;boundary=main_boundary --main_boundary Content-type:
I'm trying to make a POST request using HTTParty, in which I need the
All right, so previously I asked... SOAP Prototype AJAX SOAPAction Header Question (can't hyperlink
I am making a POST request from IE using XDomainRequest . XDomainRequest does not

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.