Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在windows中使用C提交表单_Html_C_Windows_Forms - Fatal编程技术网

Html 如何在windows中使用C提交表单

Html 如何在windows中使用C提交表单,html,c,windows,forms,Html,C,Windows,Forms,我正在尝试以html形式实现一个简单的web服务器。它必须使用C语言,并且适用于windows用户 /* FOR SERVER */ #define _CRT_SECURE_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #include <stdlib.h> #include <string.h> #include <assert.h> #include <limits.h> #includ

我正在尝试以html形式实现一个简单的web服务器。它必须使用C语言,并且适用于windows用户

/* FOR SERVER */
#define _CRT_SECURE_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <io.h>
#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib") //Winsock Library
#include <windows.h>


short SocketCreate(void)
{
    short hSocket;
    printf("Create the socket\n");
    hSocket = socket(AF_INET, SOCK_STREAM, 0);
    return hSocket;
}
int BindCreatedSocket(int hSocket)
{
    int iRetval = -1;
    int ClientPort = 8888;
    struct sockaddr_in  remote = { 0 };
    /* Internet address family */
    remote.sin_family = AF_INET;
    /* Any incoming interface */
    remote.sin_addr.s_addr = htonl(INADDR_ANY);
    remote.sin_port = htons(ClientPort); /* Local port */
    iRetval = bind(hSocket, (struct sockaddr *)&remote, sizeof(remote));
    return iRetval;
}
int main(int argc, char *argv[])
{
    WSADATA wsa;
    int socket_desc, sock, clientLen;
    struct sockaddr_in client;
    char clienttan_gelen_message[200] = { 0 };
    char serverResponse[500] = { 0 };
    char response404[50] = { 0 };
    char serverResponseXmlData[] = "<body><h1>Simple Calculator</h1><br><name>Can</name><age>26</age></body>";
    char serverResponseXmlData2[] = "<form action = localhost:8888>"
    "<div><label>Multiplicand 1: <input name = \"m\" size = \"5\"></label></div>"
    "<div><label>Multiplicand 2: <input name = \"n\" size = \"5\"></label></div>"
    "<div><input type = \"submit\" value = \"Multiply!\">< / div>"
    "< / form>";
    char message[100] = { 0 };
    const char *pMessage = "hello";

    printf("Initialising winsock...\n");
    // The WSAStartup function is used to start or initialise winsock library. 
    // It takes 2 parameters ; the first one is the version we want to load and 
    // second one is a WSADATA structure which will hold additional information after winsock has been loaded.
    if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)  // wsa will hold additional info after winsock has been loaded.
    {
        printf("Failed. Error Code : %d", WSAGetLastError());
        exit(EXIT_FAILURE);
    }
    printf("Initialised.\n");



    //Create socket
    socket_desc = SocketCreate();
    if (socket_desc == -1)
    {
        printf("Could not create socket");
        return 1;
    }
    printf("Socket created\n");
    //Bind
    if (BindCreatedSocket(socket_desc) < 0)
    {
        //print the error message
        perror("bind failed.");
        return 1;
    }
    printf("bind done\n");
    //Listen
    listen(socket_desc, 3);
    //Accept and incoming connection
    while (1)
    {
        printf("Waiting for incoming connections...\n");
        clientLen = sizeof(struct sockaddr_in);
        //accept connection from an incoming client
        sock = accept(socket_desc, (struct sockaddr *)&client, (int *)&clientLen);
        if (sock < 0)
        {
            perror("accept failed");
            return 1;
        }
        printf("Connection accepted\n");
        memset(clienttan_gelen_message, '\0', sizeof clienttan_gelen_message);
        memset(message, '\0', sizeof message);
        //Receive a reply from the client
        if (recv(sock, clienttan_gelen_message, 200, 0) < 0)
        {
            printf("recv failed");
            break;
        }
        printf("Clienttan gelen mesaj: %s\n\n\n", clienttan_gelen_message);   

        // Send some data
        //sprintf(serverResponse, "HTTP/1.0 200 OK\r\n\r\n%s\r\n", serverResponseXmlData);
        sprintf(serverResponse, "HTTP/1.0 200 OK\r\n\r\n%s\r\n", serverResponseXmlData2);

        if (send(sock, serverResponse, strlen(serverResponse), 0) < 0)
        {
            printf("Send failed");
            sprintf(response404, "HTTP/1.0 404 Not Found\r\n");
            send(sock, response404, strlen(response404), 0);
            return 1;
        }
        //closesocket(sock);
        Sleep(1000); // Note uppercase 'S'
    }

    closesocket(sock);
    WSACleanup();
    return 0;
}
服务器的
/**/
#定义\u CRT\u安全\u无\u警告
#定义\u WINSOCK\u不推荐\u无\u警告
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#pragma注释(lib,“ws2_32.lib”)//Winsock库
#包括
短SocketCreate(void)
{
短hSocket;
printf(“创建套接字\n”);
hSocket=socket(AF_INET,SOCK_STREAM,0);
返回hSocket;
}
int BindCreatedSocket(int hsSocket)
{
int-iRetval=-1;
int ClientPort=8888;
远程中的结构sockaddr_={0};
/*因特网地址族*/
remote.sin_family=AF_INET;
/*任何传入接口*/
remote.sin_addr.s_addr=htonl(INADDR_ANY);
remote.sin_port=htons(ClientPort);/*本地端口*/
iRetval=bind(hSocket,(struct sockaddr*)&remote,sizeof(remote));
返回iRetval;
}
int main(int argc,char*argv[])
{
WSADATA wsa;
内部插座描述,插座,客户;
客户端中的结构sockaddr_;
char clienttan_gelen_消息[200]={0};
char serverResponse[500]={0};
字符响应404[50]={0};
char serverResponseXmlData[]=“简单计算器
Can26”; char serverResponseXmlData2[]=“” “被乘数1:” “被乘数2:” “
” “”; 字符消息[100]={0}; const char*pMessage=“你好”; printf(“初始化winsock…\n”); //WSAStartup函数用于启动或初始化winsock库。 //它需要两个参数;第一个参数是我们要加载和修改的版本 //第二个是WSADATA结构,它将在加载winsock后保存附加信息。 if(WSAStartup(MAKEWORD(2,2),&wsa)!=0)//wsa将在加载winsock后保存其他信息。 { printf(“失败。错误代码:%d”,WSAGetLastError()); 退出(退出失败); } printf(“已初始化。\n”); //创建套接字 socket_desc=SocketCreate(); 如果(套接字描述==-1) { printf(“无法创建套接字”); 返回1; } printf(“已创建套接字”); //束缚 如果(BindCreatedSocket(套接字描述)<0) { //打印错误消息 perror(“绑定失败”); 返回1; } printf(“绑定完成”\n); //听 听(插座描述,3); //接受和传入连接 而(1) { printf(“等待传入连接…\n”); clientLen=sizeof(结构sockaddr\u in); //接受来自传入客户端的连接 sock=accept(socket_desc,(struct sockaddr*)和client,(int*)和clientLen); if(sock<0) { perror(“接受失败”); 返回1; } printf(“已接受连接”); memset(clienttan_gelen_消息,'\0',clienttan_gelen_消息大小); memset(消息'\0',消息大小); //收到客户的回复 if(recv(sock,clienttan_gelen_消息,200,0)<0) { printf(“recv失败”); 打破 } printf(“Clienttan gelen mesaj:%s\n\n\n”,Clienttan_gelen_消息); //发送一些数据 //sprintf(serverResponse,“HTTP/1.0 200正常\r\n\r\n%s\r\n”,serverResponseXmlData); sprintf(serverResponse,“HTTP/1.0 200正常\r\n\r\n%s\r\n”,serverResponseXmlData2); if(发送(sock,serverResponse,strlen(serverResponse),0)<0) { printf(“发送失败”); sprintf(响应404,“未找到HTTP/1.0 404\r\n”); 发送(sock,response404,strlen(response404),0); 返回1; } //插座; Sleep(1000);//注意大写的'S' } 插座; WSACleanup(); 返回0; } 我只向浏览器发送了一个简单的文本,但不知道如何发送表单,以便在浏览器端填写表单。我在互联网上的研究没有产生任何结果


有谁能帮我解决这个问题吗???

要处理HTML表单,服务器需要处理通过使用的GET或POST方法提交的表单数据


<>但是不要从头开始,你可能想考虑一个已经实现了这一切的库。这一个可以在Windows上运行,并且具有LGPL许可证:

要处理HTML表单,服务器需要处理通过使用的GET或POST方法提交的表单数据


<>但是不要从头开始,你可能想考虑一个已经实现了这一切的库。这一个可以在Windows上运行,并且具有LGPL许可证:

什么不起作用?如果您可以将文本发送到浏览器,那么只需发送文本,即表单的html代码。什么不起作用?如果您可以将文本发送到浏览器,那么只需发送作为表单html代码的文本即可。