Answer the question
In order to leave comments, you need to log in
How to process a request from a form on the server?
I am writing a training project, a web server in C#, and I encountered such a problem that I cannot process a request from the form on the server:
POST /php/auth.php HTTP/1.1
Host: uppdd
User-Agent: Mozilla/5.0 (Windows NT 10.0 ; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: uppdd/signin.php
Content-Type: application/x-www -form-urlencoded
Content-Length: 62
Origin: uppdd
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
login=admin&pass=secretpass&but=%D0%92%D0%BE%D0%B9%D1%82%D0%B8
This piece of code is responsible for processing the php file:
string html = AnyFile(link); // функция AnyFile(string addrs) - запускает интерпретатор php, передает путь на файл в виде строки и возвращает ответ string UTF-8
string content_type = GetContentType(link); // получает тип контента
int length = html.Length; // длина контента
string headers = $"HTTP/1.1 200 OK\nContent-type: {content_type}\nContent-Length: {length}\n\n{html}"; // заголовок
byte[] data_headers = Encoding.UTF8.GetBytes(headers); // перевод строки в байты UTF-8
client.GetStream().Write(data_headers, 0, data_headers.Length); // отправка байтов по сети клиенту
Answer the question
In order to leave comments, you need to log in
For this, https://en.wikipedia.org/wiki/Common_Gateway_Interface was invented a very long time ago
In
fact, this is the same cli but on steroids: before calling the binary and passing it to stdin a string with an encoded post, you need to set several mandatory environment variables
Couple of links:
https://stackoverflow.com/questions/4030147/how-to...
https://www.oreilly.com/openbook/cgi/ch04_02.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question