Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Edit User-Agent in C http request

I encounter bad request when I try to do a GET request with a C code on my apache2 webserver. Here is the log :

92.184.98.135 - - [20/Jul/2021:11:52:17 +0000] "GET //log.php?log=test&name=name HTTP/1.1" 400 0 "-" "-"

And when i do the same with Firefox it works :

92.184.98.135 - - [20/Jul/2021:11:59:17 +0000] "GET //log.php?log=log&name=name HTTP/1.1" 200 203 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"

Anyone knows how to disable User-Agent check with apache2 server ? Or if the problem comes from somewhere else ?

Here is the code of my function in c :

WSADATA wsa;
SOCKET sockfd;
char *message_fmt = "GET //log.php?log=%s&name=%s HTTP/1.1\r\n\r\n";
struct hostent *server;
struct sockaddr_in serv_addr;
int bytes, sent, received, total;
char message[4096],response[4096];

FILE * LOG_FILE;
LOG_FILE = fopen(file, "r+");

char log[1000] = "data:";
char ch = fgetc(LOG_FILE);

while(ch != EOF) {
    strncat(log, &ch, 1); 
    ch = fgetc(LOG_FILE);
}

fclose(LOG_FILE);

char *username = getenv("USERNAME");

sprintf(message,message_fmt,log,username);

if((sockfd = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
    {
        fprintf(DEBUG,"Could not create socket : %d" , WSAGetLastError());
    }

server = gethostbyname(adress);

memset(&serv_addr,0,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(portno);
memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length);

connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr);
total = strlen(message);
sent = 0;
do {
    bytes = send(sockfd,message+sent,total-sent,0);
    if (bytes < 0)
        {printf("ERROR writing message to socket");}
    if (bytes == 0)
        break;
    sent+=bytes;
} while (sent < total);

memset(response,0,sizeof(response));
total = sizeof(response)-1;
received = 0;
do {
    bytes = recv(sockfd,response+received,total-received,0);
    if (bytes < 0)
        {printf("ERROR reading response from socket");}
    if (bytes == 0)
        break;
    received+=bytes;
} while (received < total);

closesocket(sockfd);
WSACleanup();

As far as this code is for Windows, I use these librairies :

#include <stdio.h>
#include <winsock2.h>
#pragma comment (lib, "Ws2_32.lib")
#include <windows.h>
#include <winuser.h>
#include <string.h>

Thank you for your help !

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!