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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:24:05+00:00 2026-06-02T01:24:05+00:00

I have to send post-request using pure sockets in c++. I can’t understand where

  • 0

I have to send post-request using pure sockets in c++. I can’t understand where to send the body of the request:

int *binary = new int[bufferLength];
...

std::stringstream out(data);
out << "POST /push1_pub?id=game HTTP/1.1\n";
out << "Host: http://0.0.0.0:80\n";
out << "Content-Length: ";
out << bufferLength*sizeof(int);
out << "\r\n\r\n";
out << binary;

if (socket.send(data.c_str(), data.size()) == -1)
{
    std::cout << "Failed to send headers\n";
}
else
{
    // Send request body
    socket.send(reinterpret_cast<char*>(binary), bufferLength*sizeof(int));
    // Get the answer of server
    char buf[1024];
    std::cout << socket.recv(buf, 1024) << std::endl;
    std::cout << buf << std::endl;
}

But in buf after sending body I have:

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

What could be wrong here?


upd:

New headers I have written due to your comments:

std::string data;
std::stringstream out(data);
out << "POST /push1_pub?id=game\r\n";
out << "Host: http://localhost\r\n";
out << "Content-Length: ";
out << bufferLength << "\r\n";
out << "\r\n\r\n";
out << binary;

Still have same problem.


upd2

With this command: curl -s -v -X POST 'http://0.0.0.0/push1_pub?id=game' -d 'Test' Everything works fine and post request is generated and sent right.

  • 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-02T01:24:06+00:00Added an answer on June 2, 2026 at 1:24 am

    Your host line is wrong. It should be a simple hostname, e.g. “localhost” or “example.com”, not the http://0.0.0.0:80 URL you’ve got now.

    The host line is used by the webserver to identify which of potentially THOUSANDS of sites hosted on a single IP is being requested. The port number is also useless, since by the time you’re sending the HTTP headers, the TCP connection has already been established. And since you’re already doing an HTTP request, there’s no need to redundantly specify the protocol in use.

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

Sidebar

Related Questions

I have a program to send POST request to a server. I'm using cURL
In my app, I have send some Request to server using POST Method and
I have a problem when trying to send a POST request. The sending method
I have to send a request as https post to a third party Apache
This post is incorrectly tagged 'send' since I cannot create new tags. I have
I am using sockets to create a POST request to a given server. The
I know how to send post/get request using any HTTPClient which are explained here
I have to send get or post request to localhost: <?php if(@$_GET['option']) { echo
I have some troubles with encoding and mailing. I send post-request to php-script, when
I have an access token and i want to send the POST request and

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.