PDA

View Full Version : [c/c++] leggere un testo via http


misterx
07-03-2013, 09:13
il titolo non è sicuramente molto chiaro ma di meglio non mi veniva in mente :D

Ho un programma che resta in ascolto su una determinata porta, quando mi connetto con un browser, quello che viene mostrato sono le seguenti rughe del protocollo HTTP:

POST / HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Accept-Language: it
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:2800
Content-Length: 0
Connection: Keep-Alive
Cache-Control: no-cache

la pagina HTML che ho costruito è banalmente questa:

<html>
<head>
<title>My Page</title>
</head>
<body>
<form name="myform" action="http://localhost:5002" method="POST">
<div align="center">
<br><br>
<input type="text" size="50" value="testo da catturare">
<br><input type="submit" value="loadpp"><br>
</div>
</form>
</body>
</html>


ovviamente quello che vorrei vedere nel mio programma è solo la parte in grassetto: considerando che ciò che sto invece vedendo è corretto e considerando che nel momento in cui invio dal browser il testo in grassetto, questo impiega parecchio tempo ad inviare, come se stesse attendendo un messaggio di conferma; come posso risolvere?

grazie 1000

misterx
08-03-2013, 10:05
quello che mi servirebbe credo sia una cosa del genere per pyton ma in C




#!/usr/bin/env python
import html
import cgi
import cgitb; cgitb.enable() # for troubleshooting
print("Content-Type: text/html") # HTTP header to say HTML is following
print() # blank line, end of headers
form = cgi.FieldStorage()
say = html.escape(form["say"].value);
to = html.escape(form["to"].value);
print(say, " ", to)



https://developer.mozilla.org/en-US/docs/HTML/Forms/Sending_and_retrieving_form_data

Vincenzo1968
08-03-2013, 11:06
http://curl.haxx.se/

http://www.webdav.org/neon/

http://www.w3.org/Library/

misterx
08-03-2013, 17:09
grazie per i link ma ho risolto con un componente di bcb