Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Winsock HTML

Empfohlene Antworten

Morgen =)

ich hab seit 2 tagen nuh ein problem mit den winsock in vs10

ich möchte eine html seite aus dem web abrufen und in der console anzeigen, soweit so gut

den connect zum winsock bekoomm ich noch hin aber beim senden des Get befehls liefert er mir nur server daten zurück


HTTP/1.1 200 OK

Set-Cookie:

Set-Cookie:

Content-Length

usw

Leut der Aussage HTTP/1.1 200 OK müsste alles glatt gelaufen sein aber er zeigt es mir trotzdem nich an

// getpage.cpp : main project file.


#include "stdafx.h"

//#include <windows.h>

#include <winsock2.h>

#include <stdio.h>

#include <stdlib.h>

#include <iostream>

//#include <string.h>

#include <atlstr.h>


#pragma comment(lib, "mpr.lib")


using namespace System;

using namespace std;


void perr_exit(char* msg, int ret_code)

{

  printf("%s, Error: ",msg);

  printf("%d\n",ret_code);

  exit(ret_code);

}


void usage(char* prgname)

{

  printf("\nUsage:\t");

  printf("%s <URL> [<File>]\n",prgname);

  printf("\tURL:  Website URL\n");

  printf("\tFile: Optional File to store the Website\n");

  exit(0);

}


int main(int argc, char * argv[])

{

     char* url;

  char* site;

  char* host;

  char  buf[1024];

  char  send_buf[256];

  char  recv_buf[256];

  long  rc;

  FILE* target_file;

  char  uses_file=0;

  char* write_ptr;

  SOCKET s;

  SOCKADDR_IN addr;

  WSADATA wsa;

  HOSTENT* hent;


  if(WSAStartup(MAKEWORD(2,0),&wsa))

    perr_exit("WSAStartup failed",WSAGetLastError());

	s=socket(AF_INET, SOCK_STREAM, 0);

  addr.sin_family=AF_INET;

  addr.sin_port=htons(80);


	//eingeber der URL

    printf("\nURL: ");

		//scanf("%s",buf);

		sprintf(buf,"dtdragonfighter.dt.funpic.de/index.html");

		//sprintf(host,"http://dtdragonfighter.dt.funpic.de");

		//sprintf(site,"/test.html");

		url=buf;

	//Überprüfen der url	

  if(strncmp("http://",url,7)==0)

    host=url+7;

  else

    host=url;

//---------------------------------------------

  if((site=strchr(host,'/'))!=0)

    *site++='\0';

  else

    site=host+strlen(host); /* \0 */


  printf("Host: %s\n",host);

  printf("Site: %s\n",site);

  printf("Connecting....\n");

	//Fehler abfangen

  if((addr.sin_addr.s_addr=inet_addr(host))==INADDR_NONE)

  {

    if(!(hent=gethostbyname(host)))

      perr_exit("Cannot resolve Host",WSAGetLastError());


    strncpy((char*)&addr.sin_addr.s_addr,hent->h_addr,4);


    if(addr.sin_addr.s_addr==INADDR_NONE)

      perr_exit("Cannot resolve Host",WSAGetLastError());

  }


  if((s=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)

    perr_exit("Cannot create Socket",WSAGetLastError());


  if( connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR)))

    perr_exit("Cannot connect",WSAGetLastError());


  printf("Connected to %s...\n",host);


	sprintf(send_buf,"put /%s HTTP/1.1.0\r\n Host: http://%s/%s?Version=ABBUND:80\r\n\r\n" ,site,buf,site);


	printf("%s\n",send_buf);

	if((send(s,send_buf,strlen(send_buf),0))<strlen(send_buf))

    perr_exit("Cannot send Data",WSAGetLastError());


  printf("----Result----\n");


	//ausgabe des Empfangens

  while((rc=recv(s,recv_buf,255,0))>0)

  {

    recv_buf[rc]='\0';

    printf("%s",recv_buf);

  }

	//Ausgeben der fehlermeldung im recive

	printf("recv failed: %d\n", WSAGetLastError());

	//done

  printf("\nDONE!");

 //close socket

	closesocket(s);


    return 0;

}


PS: Rechtschreibfehler sind beabsichtigt ^^

PSS: Code is nich schön ich weiss

Close()

hab fehler gefunden

war im String den cih an den Server gesendet hab

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.