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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:10:29+00:00 2026-05-18T08:10:29+00:00

I am using PHP to perform a POST request from a socket. Here is

  • 0

I am using PHP to perform a POST request from a socket. Here is a code snippet:

// open a socket connection on port 80
$fp = fsockopen($host, 80);

// send the request headers:
fwrite($fp, "POST $path HTTP/1.1\r\n");
fwrite($fp, "Host: $host\r\n");
fwrite($fp, "Referer: $referer\r\n");
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-length: ". strlen($data) ."\r\n");
fwrite($fp, "Connection: close\r\n\r\n");
fwrite($fp, $data);

$result = ''; 
while(!feof($fp)) {
    // receive the results of the request
    $result .= fread($fp, 5000);
}

However, each line of the response seems to be prefixed with its length in hex. Why is that happening?

For example, a test cgi script, to which I post, returns its environment:

BASH=/bin/bash
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()

But my PHP function ends up with this:

f
BASH=/bin/bash

69
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath

10
BASH_ALIASES=()
  • 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-18T08:10:30+00:00Added an answer on May 18, 2026 at 8:10 am

    You should use HTTP/1.0, because 1.1 servers typically respond with the Transfer-Encoding: chunked (= which are the parts prefixed by hex numbers).

    You could try to send a request begging for identity content encoding, but chunked is required from all HTTP/1.1 clients as transfer format, so that might be unreliabe.

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

Sidebar

Related Questions

I perform an AJAX request to a PHP script in JavaScript and by using
I'm making simple http post request using libcurl to index.php file on my web
Im trying to shorten a url using ggole api's.Here is my php code .It
Trying to post a status update using facebook php sdk. Code posted below. As
I was looking for way to perform form (post) request with SOAP using jQuery/AJAX.
From one tutorials here: Post a reply on a comment in Facebook using cURL
If I'm using PHP to perform a cURL POST to a remote server running
Using php I am trying to get some data from a .csv file which
I am trying to post to a REST service using PHP cURL but I'm
I've used the php-sdk to perform the login using facebook. What should I store

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.