Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Recensione vivo X300 Pro: è ancora lui il re della fotografia mobile, peccato per la batteria
Recensione vivo X300 Pro: è ancora lui il re della fotografia mobile, peccato per la batteria
vivo X300 Pro rappresenta un'evoluzione misurata della serie fotografica del produttore cinese, con un sistema di fotocamere migliorato, chipset Dimensity 9500 di ultima generazione e l'arrivo dell'interfaccia OriginOS 6 anche sui modelli internazionali. La scelta di limitare la batteria a 5.440mAh nel mercato europeo, rispetto ai 6.510mAh disponibili altrove, fa storcere un po' il naso
Lenovo Legion Go 2: Ryzen Z2 Extreme e OLED 8,8'' per spingere gli handheld gaming PC al massimo
Lenovo Legion Go 2: Ryzen Z2 Extreme e OLED 8,8'' per spingere gli handheld gaming PC al massimo
Lenovo Legion Go 2 è la nuova handheld PC gaming con processore AMD Ryzen Z2 Extreme (8 core Zen 5/5c, GPU RDNA 3.5 16 CU) e schermo OLED 8,8" 1920x1200 144Hz. È dotata anche di controller rimovibili TrueStrike con joystick Hall effect e una batteria da 74Wh. Rispetto al dispositivo che l'ha preceduta, migliora ergonomia e prestazioni a basse risoluzioni, ma pesa 920g e costa 1.299€ nella configurazione con 32GB RAM/1TB SSD e Z2 Extreme
AWS re:Invent 2025: inizia l'era dell'AI-as-a-Service con al centro gli agenti
AWS re:Invent 2025: inizia l'era dell'AI-as-a-Service con al centro gli agenti
A re:Invent 2025, AWS mostra un’evoluzione profonda della propria strategia: l’IA diventa una piattaforma di servizi sempre più pronta all’uso, con agenti e modelli preconfigurati che accelerano lo sviluppo, mentre il cloud resta la base imprescindibile per governare dati, complessità e lock-in in uno scenario sempre più orientato all’hybrid cloud
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 25-03-2004, 17:45   #1
fabiot
Member
 
Iscritto dal: Apr 2003
Città: Roma
Messaggi: 204
[C] Leggere un file di testo da un sito Web

ho necessità di leggere un file di testo presente in un sito web.
Devo utilizzarlo in una applicazione dialog Based scritta in Visual C++,
ma il codice può essere anche in C normale.

Mi servirebbe memorizzare il contenuto della prima linea del file e memorizzarlo in una stringa.

Come posso fare?
Grazie!
fabiot è offline   Rispondi citando il messaggio o parte di esso
Old 25-03-2004, 20:11   #2
cionci
Senior Member
 
L'Avatar di cionci
 
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
Ti riesce usare i socket ?
Questa cosa dovrebbe essere abbastanza facile da realizzare...

Se l'indirizzo del file è http://www.nome.it/percorso/nomefile.html devi connetterti al server sula porta 80 ed inviare questa richiesta:

GET /percorso/nomefile.html HTTP/1.1\n\r
Host: www.nome.it\n\r\n\r

Otterrai come risposta una lista di queste righe:

Header: valore\n\r

Dopo l'ultima riga c'è uno \n\r ulteriore...a quel punto cominciano i dati del file (cioè quello che ti interessa)...
cionci è offline   Rispondi citando il messaggio o parte di esso
Old 25-03-2004, 22:37   #3
vici_1
Senior Member
 
L'Avatar di vici_1
 
Iscritto dal: Aug 2002
Messaggi: 581
Ho fatto delle prove con l'intento di scaricare delle pagine da internet.
Se hai la pazienza di studiarti questo sorgente in C, che ho scopiazzato ed adatatto per le mie prove, dovresti trovare il sistema per fare cio' che ti serve.
Dopo averlo compilato, devi eseguirlo in una finestra DOS digitando : "prova_client_web client www.google.it" Ti verra' printato a video la prima parte della pagina html di google(1024 + 1024 byte) . Adattando la GET come ti ha suggerito Cionci, dovresti ottenere nel buffer di ritorno il risultato che cerchi.
Ciao.
Codice:
#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>

//#define PORT 6644
#define PORT 80

//#define MESSAGE1 "Hello from client\0"
//#define MESSAGE2 "Connection Closing\0"

//User-Agent: Opera/6.05 (Windows XP; U)  [en]
//Host: 127.0.0.1
//Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
//Accept-Language: it, en
//Accept-Charset: windows-1252;q=1.0, utf-8;q=1.0, utf-16;q=1.0, iso-8859-1;q=0.6,
// *;q=0.1
//Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
//Cache-Control: no-cache
//Connection: Keep-Alive, TE
//TE: deflate, gzip, chunked, identity, trailers

//¦"'

#define MESSAGE6 "GET /prova1.html HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n\0"    
//#define MESSAGE7 "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n\0"    
//#define MESSAGE7 "GET / HTTP/1.1\r\nAccept-Language: it\r\nHost: 127.0.0.1\r\n\r\n\0"    
//#define MESSAGE7 "GET /servlet/HomeController?target=SearchQuotes&param_iniziale=A HTTP/1.1\r\nAccept-Language: it\r\nHost: www.google.it\r\n\r\n\0"    
#define MESSAGE7 "GET / HTTP/1.1\r\nAccept-Language: it\r\nHost: www.google.it\r\n\r\n\0"    

#define MAX_STRING 1024

void client(char *);
void error(char *);
int InitializeWinsock(WORD );
void Usage();

int main(int argc, char *argv[])
{
	if ( argc < 2 ) Usage();

	if (strcmp(argv[1], "client") == 0 )
	{
		// initialize wsock32.dll, requesting winsock 1.1
		if (argc!=3 ) Usage();
		if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
		client(argv[2]);
		WSACleanup();
	}
	return 0;
}

void client(char * server_IP)
{
SOCKET fd; 			// "file" descriptor for the network socket
SOCKADDR_IN saddr;
char buf[MAX_STRING];
	printf("1\n");
//prova
    struct hostent *h;

    //if ((h=gethostbyname("www.cadport.it")) == NULL) {  /* get the host info */
    if ((h=gethostbyname(server_IP)) == NULL) {  /* get the host info */
		error("gethostbyname");
        exit(1);
    }
        printf("Host name  : %s\n", h->h_name);
        printf("IP Address : %s\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
	//------------------
	if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
		error("Client: socket not connected ");
	printf("2\n");

	saddr.sin_family = AF_INET;
	//saddr.sin_addr.s_addr = inet_addr(server_IP); 
	saddr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)h->h_addr))); 
	saddr.sin_port = htons(PORT);
	
	printf("3\n");
	// request connection to server socket (remote machine)
	if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
		error("Client: connect ");
	printf("4\n");

	//if( send(fd, MESSAGE1, strlen(MESSAGE1)+1, 0) == SOCKET_ERROR )
	//	error("Server: sending failure ");
	//if( send(fd, MESSAGE6, strlen(MESSAGE6)+1, 0) == SOCKET_ERROR )
	if( send(fd, MESSAGE7, strlen(MESSAGE7)+1, 0) == SOCKET_ERROR )
		error("Server: sending failure ");
 	printf("5\n");

	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
		error("Client: receiving failure ");
	printf("6\n");

	printf("Server echoed1 '%s' \n",buf);
		
	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
		error("Client: receiving failure ");
	printf("7\n");

	printf("Server echoed2 '%s' \n",buf);

	//if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
	//	error("Client: receiving failure ");
	//printf("8\n");

	//printf("Server echoed3 '%s' \n",buf);
	
	printf("Sending 'Connection Closing' command\n\n");

	//if( send(fd, MESSAGE2, strlen(MESSAGE2)+1, 0) == SOCKET_ERROR )
	//	error("Server: sending failure ");

	if (closesocket(fd) == SOCKET_ERROR)
		error("Client: closing socket ");
}



/**********************************************
* Windows Sockets Initialization              *
**********************************************/

int InitializeWinsock(WORD wVersionRequested)
{
WSADATA wsaData;
int err;

	err = WSAStartup(wVersionRequested, &wsaData);

	// ritorna errore se, ad esempio, l'applicazione supporta al massimo
	// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
	if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll 

	// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
	//  and in wVersion the minimum of its high version and wVersionRequested.
	//  wVersion is the The version of the Windows Sockets specification 
	//  that the Windows Sockets DLL expects the caller to use.

	// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora 
	//  verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
	//  con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione 
	//  vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi 
	//  in questo caso

	// Tell the user that we couldn't find a usable winsock.dll.
	if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;

	//Everything is fine: proceed
	return 1;
}


/**********************************************
* Error Handling Functions                    *
**********************************************/

void Usage()
{
	printf("\n\t Usage: tcp_sock server | client ip_server_address\n\n");
	exit(1);
}

// define to save space
#define PERR(X) fprintf(stderr, X); break

void error(char* string) {
int err;
    
	fprintf(stderr, "%s", string);

	err= WSAGetLastError();
    
	//in Windows, gli errori dovuti ai sockets sono mappati oltre 10000
   	switch (err)
	{
	case WSANOTINITIALISED: 
             PERR("A successful WSAStartup() must occur before using this API.");
	case WSAENETDOWN:
             PERR("The Windows Sockets implementation has detected that the network subsystem has failed.");
	case WSAEAFNOSUPPORT:
             PERR("The specified address family is not supported.");
	case WSAEINPROGRESS:
             PERR("A blocking Windows Sockets operation is in progress.");
	case WSAEMFILE:
             PERR("No more file descriptors are available.");
	case WSAENOBUFS:
             PERR("No buffer space is available. The socket cannot be created.");
	case WSAEPROTONOSUPPORT:
             PERR("The specified protocol is not supported.");
	case WSAEPROTOTYPE:
             PERR("The specified protocol is the wrong type for this socket.");
	case WSAESOCKTNOSUPPORT:
             PERR("The specified socket type is not supported in this address family.");
   	case WSAEADDRINUSE:
             PERR("The specified address is already in use. (See setsockopt() SO_REUSEADDR option)");
    	case WSAEFAULT:
             PERR("The namelen argument is too small (less than the size of a struct sockaddr).");
    	case WSAEINTR:
             PERR("The (blocking) call was canceled via WSACancelBlockingCall()");
	case WSAEINVAL:
             PERR("The socket is already bound to an address.");
   	case WSAENOTSOCK:
             PERR("The descriptor is not a socket.");
    	case WSAEADDRNOTAVAIL:
             PERR("Address not availabile");
	case WSAEISCONN:
             PERR("The socket is already connected.");
	case WSAEOPNOTSUPP:
             PERR("The referenced socket is not of a type that supports the listen() operation.");
	case WSAEWOULDBLOCK:
             PERR("The socket is marked as non-blocking and no connections are present to be accepted.");
	case WSAECONNREFUSED:
             PERR("The attempt to connect was forcefully rejected.");
	case WSAEDESTADDRREQ:
             PERR("A destination address is required.");
	case WSAENETUNREACH:
             PERR("The network can't be reached from this host at this time.");
	case WSAETIMEDOUT:
             PERR("Attempt to connect timed out without establishing a connection");
       	case WSAECONNRESET:
             PERR("Connection reset");
       
	default:
             fprintf(stderr, "Error reported by WSAGetLastError= %d\n Check winsock.h.\n\n", err); break;
	};

	exit(1);
	}
vici_1 è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2004, 00:26   #4
cionci
Senior Member
 
L'Avatar di cionci
 
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
Come al solito confondo sempre \n\r e \r\n
cionci è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2004, 23:08   #5
fabiot
Member
 
Iscritto dal: Apr 2003
Città: Roma
Messaggi: 204
ho potuto leggere le risposte solo oggi. Grazie le analizzerò domattina, in ogni caso, nel frattempo, ho utilizzato la funzione

URLDownloadToFile(NULL,"www.sito.com/file.txt","file locale.txt",0,NULL)

e sembra che possa fare al mio caso.
fabiot è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Recensione vivo X300 Pro: è ancora lui il re della fotografia mobile, peccato per la batteria Recensione vivo X300 Pro: è ancora lui il...
Lenovo Legion Go 2: Ryzen Z2 Extreme e OLED 8,8'' per spingere gli handheld gaming PC al massimo Lenovo Legion Go 2: Ryzen Z2 Extreme e OLED 8,8'...
AWS re:Invent 2025: inizia l'era dell'AI-as-a-Service con al centro gli agenti AWS re:Invent 2025: inizia l'era dell'AI-as-a-Se...
Cos'è la bolla dell'IA e perché se ne parla Cos'è la bolla dell'IA e perché se...
BOOX Palma 2 Pro in prova: l'e-reader diventa a colori, e davvero tascabile BOOX Palma 2 Pro in prova: l'e-reader diventa a ...
Ecco i saldi di fine anno Amazon, 34 off...
iPhone Fold: scorte limitate al lancio m...
OpenAI porterà la pubblicità in ChatGPT ...
TSMC aumenterà ancora i prezzi: nel 2026...
Marvel pubblica anche il secondo teaser ...
Nuovo accordo tra xAI e il Pentagono: l'...
La famiglia Xiaomi 17 sta per registrare...
Nuove auto elettriche che vedremo sul me...
E-bike illegali, a Verona il più ...
Quali sono i giochi più venduti su Steam...
HONOR sta per lanciare un nuovo smartpho...
Jared Isaacman sarà alla guida de...
Il Tesla Cybertruck non arriverà ...
Xiaomi Watch 5 è ufficiale: architettura...
CD Projekt vende GOG: il co-fondatore Mi...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 09:20.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Served by www3v