How does a httpPlatformHandler program get posted data?

Roland Smith 1 Reputation point
2022-06-15T01:30:09.54+00:00

I wrote a httpPlatformHandler server app using C++ and Winsock functions. When the URL is called with GET from a browser, recv returns headers. If I call the URL from a program that does a GET and includes data, I see the Content-Length header but no data. If I do a POST, recv returns nothing.

I need to know how my app can access posted data.

Another issue is that when calling from a browser, occasionally recv returns nothing or a bad gateway error.

If Winsock expert would like to look at the code, I can post that.

Internet Information Services
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,454 questions
0 comments No comments
{count} votes

8 answers

Sort by: Newest
  1. Roland Smith 1 Reputation point
    2022-06-26T02:34:55.387+00:00

    I have it working but the forum won't let me post any details.


  2. Xiaopo Yang - MSFT 11,661 Reputation points Microsoft Vendor
    2022-06-24T09:15:02.863+00:00

    recv returns -1 and WSAGetLastError returns WSAEWOULDBLOCK which means no data is queued to be read from the socket.
    The problem should be the request is read partially or hasn't been read when the execution run through while.
    For a simply solution, according to socket_dumb_http, you can check the last "\r\n\r\n" to see whether the request is transmitted completely or not.

    0 comments No comments

  3. Roland Smith 1 Reputation point
    2022-06-17T22:49:01.74+00:00

    The data being sent with the GET is only 16 characters. My buffer is 1024 and all the headers total about 350.

    Do you have a code example you can point me to? When I use POST, recv returns nothing.

    0 comments No comments

  4. Bruce (SqlWork.com) 58,206 Reputation points
    2022-06-17T19:44:13.893+00:00

    couple issues with this code:

        ReceivedData.clear();  
             do {  
                 memset(szRecvBuffer, 0x00, sizeof(szRecvBuffer));  
                 iResult = recv(ClientSocket, szRecvBuffer, sizeof(szRecvBuffer) - 1, 0);  
                 if (iResult > 0) {  
                     ReceivedData.append(szRecvBuffer);  
                 }  
             } while (iResult != SOCKET_ERROR);  
    

    not sure it handles a partial buffer. but the big issue is it not getting the content size to know when to stop reading. your logic should read and parse the headers first. this will tell you lots of information about what is next in the stream (maybe another request)

    1) the content type and size
    2) whether this is a range request
    3) whether this is chunked request
    4) the encoding of the request data if any.


  5. Roland Smith 1 Reputation point
    2022-06-17T19:23:31.257+00:00

    My server app currently is FastCGI written in C++. It supports GET from a web browser, returning either XML, JSON, or a PDF report. It also supports a desktop app written in C++ that uses WinHTTP to send parameters to code in the server app which uses the parameters to retrieve data from a database and return it to the client.

    I had posted about a fairly minor issue on StackOverflow and one of their experts suggested re-writing it using httpPlatformHandler. Conceptually it seems easy and has some advantages specific to my app but it doesn't seem to be working the way I want. The recv function sometimes returns nothing, sometimes the caller gets a Bad Gateway error, and I can't figure out how to access posted data. There are zero examples on the web that I can find.

    Does HTTP Server API handle automatically running multiple copies of my app depending on load? That is something FastCGI and httpPlatformHandler does for me.