-2

For some reason i'm not aware of POST requests don't work. I'm pretty sure the problem is with the POST string "POST /profile.php HTTP/1.1\r\nid=2323\r\nContent-Length: \r\n\r\n". GET requests work properly but not POST requests.

I connect to the server through port 443 using TLS VER 1.0

Here is the error code I got from the server.. EDIT: I'm trying to edit this post to fix it up and it's telling me that my post is mostly code but not anymore I hope.

85 bytes of data sent

HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Date: Fri, 22 Nov 2019 06:56:20 GMT
Connection: close
Content-Length: 2959

<!DOCTYPE html>
<html lang="en" id="facebook">
  <head>
    <title>Facebook | Error</title>
    <meta charset="utf-8">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="cache-control" content="no-store">
    <meta http-equiv="cache-control" content="max-age=0">
    <meta http-equiv="expires" content="-1">
    <meta http-equiv="pragma" content="no-cache">
    <meta name="robots" content="noindex,nofollow">
    <style>
      html, body {
        color: #141823;
        background-color: #e9eaed;
        font-family: Helvetica, Lucida Grande, Arial,
                     Tahoma, Verdana, sans-serif;
        margin: 0;
        padding: 0;
        text-align: center;
      }

      #header {
        height: 30px;
        padding-bottom: 10px;
        padding-top: 10px;
        text-align: center;
      }

      #icon {
        width: 30px;
      }

      h1 {
        font-size: 18px;
      }

      p {
        font-size: 13px;
      }

      #footer {
        border-top: 1px solid #ddd;
        color: #9197a3;
        font-size: 12px;
        padding: 5px 8px 6px 0;
      }
    </style>
  </head>
  <body>
    <div id="header">
      <a href="//www.facebook.com/">
        <img id="icon" src="//static.facebook.com/images/logos/facebook_2x.png" />
      </a>
    </div>
    <div id="core">
      <h1 id="sorry">Sorry, something went wrong.</h1>
      <p id="promise">
        We're working on it and we'll get it fixed as soon as we can.
      </p>
      <p id="back-link">
        <a id="back" href="//www.facebook.com/">Go Back</a>
      </p>
      <div id="footer">
        Facebook
        <span id="copyright">
          &copy; 2019
        </span>
        <span id="help-link">
          &#183;
          <a id="help" href="//www.facebook.com/help/">Help Center</a>
        </span>
      </div>
    </div>
    <script>
      document.getElementById('back').onclick = function() {
        if (history.length > 1) {
          history.back();
          return false;
        }
      };

      // Adjust the display based on the window size
      if (window.innerHeight < 80 || window.innerWidth < 80) {
        // Blank if window is too small
        document.body.style.display = 'none';
      };
      if (window.innerWidth < 200 || window.innerHeight < 150) {
        document.getElementById('back-link').style.display = 'none';
        document.getElementById('help-link').style.display = 'none';
      };
      if (window.innerWidth < 200) {
        document.getElementById('sorry').style.fontSize = '16px';
      };
      if (window.innerWidth < 150) {
        document.getElementById('promise').style.display = 'none';
      };
      if (window.innerHeight < 150) {
        document.getElementById('sorry').style.margin = '4px 0 0 0';
        document.getElementById('sorry').style.fontSize = '14px';
        document.getElementById('promise').style.display = 'none';
      };
    </script>
  </body>
</html>


3215 bytes received
  • Why is this question tagged with C++? – Thomas Sablik Nov 22 '19 at 08:40
  • Well I could either tag it C or C++, but since i'm using sspi schannel with C++, I tagged it C++ – Kazem Abousetta Nov 22 '19 at 19:33
  • There is no C++ code. How could a C++ developer help you? Post C++ code or remove the tag. – Thomas Sablik Nov 22 '19 at 22:10
  • I don't understand your logic behind, "if there is no c++ code, then it is not c++". For you to send a POST request in C++ it requires you to properly format it as in proper new lines and all that crazy stuff. Other programming languages aren't the same. Almost everyone who programmed with winsock in c++ understands that this "POST /profile.php HTTP/1.1\r\nid=2323\r\nContent-Length: \r\n\r\n" is only applicable with C++ and similar languages. – Kazem Abousetta Nov 22 '19 at 23:18
  • You tagged the question with C++ to reach people with C++ experience but C++ experience won't help with this question. You could also tag your operating system or the manufacturer of your display. Of course it's related in some way but it won't help. Nothing in this question can be answered with knowledge from C++ standard, C++ libraries or C++ compilers. It's very winsock specific. – Thomas Sablik Nov 22 '19 at 23:25

1 Answers1

1

Instead of making POST request, you could just use a GET request instead and do this

"GET /profile.php?id=2323 HTTP/1.1\r\nConnection: close\r\n\r\n"

It mostly depends on the server you are connecting to, so if that doesn't work, try using HTTP v1.0

"GET /profile.php?id=2323 HTTP/1.0\r\nConnection: close\r\n\r\n"

If that still does not work, you might have to specifiy the host, mostly when you are trying to fetch an image from a website that looks something like https://en30.picwebsite.com

"GET /profile.php?id=2323 HTTP/1.1\r\nHost: en30.picwebsite.com\r\nConnection: close\r\n\r\n"

Try both HTTP v1.0 and v1.1

If all did not work, make sure you are connecting using SSL/TLS if it is a secure website. If you are, then try a main page simple GET request "GET / HTTP/1.1\r\nConnection: close\r\n\r\n" also both HTTP v1.0 and v1.1

If that also did not work then aha it maybe an issue with your Socket/TLS implementation or the server.

EDIT:

I finally figured out how to make a proper POST request. You have to always specify the content length in POST requests, and the content length is supposed to be the size of your query for example - "std::string("id=2323&file=funpic&name=rosh").size() and the query has to go at the end of the request string, in my case after Connection: close\r\n\r\n

For example my earlier query where I wanted to change id to 2323 /profile.php?id=2323, id do this -

std::string query = "id=2323";
std::string request = "POST /profile.php HTTP/1.1\r\nContent-Length: " + 
std::to_string(query.size()) + "\r\nConnection: close\r\n\r\n" + query;
send(sock, request.c_str(), request.size(), 0);

You could also add \r\n after the query and it would still work id=2323\r\n

Make sure you add the query only after the full request, because the query is supposed to be inside the content of the website not in the header.