Hallo, ich habe hier Problem beim auslesen einer adresse



  • //CODE im wesentlichen aus msdn abgeschrieben... funktioniert im Prinzip...
    // ganz unten in diesem Beitrag die Fragestellung...
    
    void TESTSOCKET::Test1a(){
    
    	WORD wPort = 443;//default 80 https port  443 ?
    	int iResult = 0;int nErr;
    
    	const char AS[] =("54.83.203.67");// www.artistsignal.com
    	const char* pip = &AS[0];
    
    	//HTTP GET ANFRAGE 
    	String sRequest = "";
    	sRequest += "GET https://www.artistsignal.com/ HTTP/1.1\r\n";
    	sRequest += "Host: artistsignal.com\r\n";
    	sRequest += "Connection: close\r\n\r\n"; //keep-alive
    
    	StringToDebugWindow(sRequest, true);
    
    	WSADATA wsaData;
    	if (WSAStartup (MAKEWORD(1, 1), &wsaData) != 0) {
    	    //fprintf (stderr,
    	       // "WSAStartup(): Kann Winsock nicht initialisieren.\n");
    	    return;
    	}
    	//--------------------------------------------------------------
    
        addrinfo hints;
        addrinfo* presult;
        addrinfo* ptr;
    
        ZeroMemory( &hints, sizeof(hints) );
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_protocol = IPPROTO_TCP;
    
        // Resolve the server address and port 
        iResult = getaddrinfo( (PCSTR)pip , (PCSTR)AsString(wPort) , &hints, &presult);//DEFAULT_PORT = 80  27015 ?
    
    	sockaddr* psa = presult->ai_addr;
    	USHORT sa_fam = psa->sa_family;
    	String sdumm = (String)(psa->sa_data);
        if ( iResult != 0 ) {
            nErr = WSAGetLastError();
            WSACleanup();
            return;
        }
    
         //--------------------------------------------------------------
    
    	int sockfd = INVALID_SOCKET;
    	// Attempt to connect to an address until one succeeds
        for(ptr=presult; ptr != NULL ;ptr=ptr->ai_next) {
    
    		sockfd = socket(presult->ai_family, presult->ai_socktype, presult->ai_protocol);
    		//ZUSATZ Socket unlocken
    		u_long iMode = 0;
    		iResult = ioctlsocket(sockfd, FIONBIO, &iMode);
    		if (iResult != NO_ERROR){
    	  		nErr = WSAGetLastError();
    	  		WSACleanup();
    			return;
    	  	}
    
    		int b = connect(sockfd, ptr->ai_addr, (int)ptr->ai_addrlen);
    			if ( b == -1) {
    
    				closesocket(sockfd);
    		    	sockfd = INVALID_SOCKET;
    		    	continue;
    		}
    
    		break;
        }
    
    	freeaddrinfo(presult);
    
    		const char *sendbuf = sRequest;
    
    		//char* sendbuf = "this is a test" //???????;
    		iResult = send( sockfd, sendbuf, (int)strlen(sendbuf), 0 );
    		StringToDebugWindow( (String)("Bytes Sent: " + AsString(iResult)), true);
    		if (iResult == SOCKET_ERROR) {
            	nErr = WSAGetLastError();
            	closesocket(sockfd);
            	WSACleanup();
            	return;
        	}
    
        	int cloop = 0;
        	// Receive until the peer closes the connection	
    		char recvbuf[512];
    
    	    iResult = 1;
    		do {
    			if (readable(sockfd)){
    
    		        iResult = recv(sockfd, recvbuf, 512, 0);//MSG_PEEK
    
    		        if ( iResult > 0 ){
    
    					String ss = (String)recvbuf;
    		        	StringToDebugWindow(ss, true);
    
    				}
    		        else if ( iResult == 0 ){
    		            StringToDebugWindow("Connection closed", true);
    		        }
    		        else{
    		            StringToDebugWindow("recv failed: " + AsString( WSAGetLastError()), true);
    		        }
    			}
    
    	    } while( iResult > 0 );
    
    	closesocket(sockfd);
    	WSACleanup();
    
    }
    

    //END CODE
    // EGREBNISSE
    //FEHLER 301---------------------------

    Anfrage:
    GET / HTTP/1.1
    Host: www.artistsignal.com
    Connection: close

    auf port 80 <----------------

    Bytes Sent: 65
    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.1.19
    Date: Sun, 23 Nov 2014 19:38:02 GMT
    Content-Type: text/html
    Content-Length: 185
    Connection: close
    Location: https://artistsignal.com/

    <html>
    <head><title>301 Moved Permanently</title></head>
    <body bgcolor="white">
    <center><h1>301 Moved Permanently</h1></center>
    <hr><center>nginx/1.1.19</center>
    </body>
    </html>

    Connection closed
    //----- moved permanently - soweit, so gut ....-------------------

    ????????????????????????????????????????????????
    ABER???????????????????????????????????????????????????????????????????????????
    Ergebnis bei:

    GET / HTTP/1.1
    Host: artistsignal.com
    Connection: close

    GET https://www.artistsignal.com/ HTTP/1.1
    Host: artistsignal.com
    Connection: close

    auf port 443 <----------------

    Bytes Sent: 65
    HTTP/1.1 400 Bad Request
    Server: nginx/1.1.19
    Date: Sun, 23 Nov 2014 19:30:15 GMT
    Content-Type: text/html
    Content-Length: 271
    Connection: close

    <html>
    <head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
    <body bgcolor="white">
    <center><h1>400 Bad Request</h1></center>
    <center>The plain HTTP request was sent to HTTPS port</center>
    <hr><center>nginx/1.1.19</center>
    </body>
    </html>

    Connection closed
    ??????????????????????????????????????????????????????????????????????????
    beim Web sniffer klappts hingegen 😕

    Connect to 54.83.203.67 on port 443 ... ok

    GET / HTTP/1.1[CRLF]
    Host: artistsignal.com[CRLF]
    Connection: close[CRLF]

    User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)[CRLF]
    Accept-Encoding: gzip[CRLF]
    Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]
    Cache-Control: no-cache[CRLF]
    Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]
    Referer: http://web-sniffer.net/[CRLF]
    [CRLF]

    Status: HTTP/1.1 200 OK
    Server: nginx/1.1.19
    ... etc...



  • die Frage ist:
    Stimmt was mitt der Syntax der Anfrage nicht ?
    oder mach ich im Code irgendwas falsch ?
    Vielen Dank für eure Mühe


  • Mod

    Die Antwort steht in der Fehlermeldung.

    Du kannst auf dem HTTPS Port keine HTTP Anfrage hinsenden. Du musst das schon korrekt mit SSL/TLS Verschlüsseln. Dein Websniffer wird das Transparent für dich machen.



  • Herzichen Dank!


Anmelden zum Antworten