I'm getting these two errors! I'm using Visual Studio 2010 and Win 7.
IntelliSense: identifier is undefined
IntelliSense: a value of type cannot be used to initialize an entity of type
#include <stdio.h>
#include <string.h>
#include <stdafx.h>
#include <winsock2.h>
#include <stdlib.h>
#include <ws2tcpip.h>
static const char *BODY = "SomeVariable1=foo&SomeVariable2=bar";
static const char *HEADERS = "POST /test.php HTTP/1.0\r\n"
"Host: 192.168.168.40\r\n"
"Accept: */*\r\n"
"Connection: keep-alive\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: ";
int main()
{
struct addrinfo req, *res;
memset(&req, 0, sizeof(req));
req.ai_family = AF_UNSPEC;
req.ai_socktype = SOCK_STREAM;
if (getaddrinfo("192.168.168.40", "http", &req, &res) < 0)
{
perror("getaddrinfo");
return -1;
}
int s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s < 0)
{
perror("socket");
return -1;
}
if (connect(s, res->ai_addr, res->ai_addrlen) < 0)
{
perror("connect");
close(s);
return -1;
}
char *buffer = malloc(strlen(BODY) + strlen(HEADERS) + 256);
sprintf(buffer, "%s%d\r\n\r\n%s\r\n\r\n", HEADERS, strlen(BODY), BODY);
if (send(s, buffer, strlen(buffer), 0) < 0)
{
perror("send");
}
else
{
char recvbuffer[8192] = { 0 };
int recvcount = 0;
recvcount = recv(s, recvbuffer, sizeof(recvbuffer), 0);
while (recvcount > 0)
{
printf("Received: %s", recvbuffer);
recvcount = recv(s, recvbuffer, sizeof(recvbuffer), 0);
}
printf("\n");
}
free(buffer);
close(s);
return 0;
}