Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Клуб программистов > Свободное общение
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 21.07.2025, 09:05   #1
test2me
Новичок
Джуниор
 
Регистрация: 21.07.2025
Сообщений: 5
По умолчанию Спамеры в России мало спамят обычно...а еще они покупают готовый интернет-трафик.

Спамеры в России мало спамят обычно...а еще они покупают готовый интернет-трафик.

Вот исходные коды, основы запроса к сайту на низком уровне на c++:
Код:
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <iostream>
using namespace std;


static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(void)
{
  CURL *curl;
  CURLcode res;
  std::string readBuffer;

  curl = curl_easy_init();
  if(curl) {
    // url
    curl_easy_setopt(curl, CURLOPT_URL, "https://google.ru");
    // https
    curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_3);
    //create text from url
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    //send string readbuffer as link to the callback function
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    //send request
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    std::cout << readBuffer << std::endl;
  }
  return 0;
}
этот код делает запрос низкого уровня к какому-либо сайту.

но как пишется к нему, авторизация, регистрация и накручивание друзей в соц.сети я не знаю.
test2me вне форума Ответить с цитированием
Старый Вчера, 10:14   #2
blackstrip
Форумчанин
 
Аватар для blackstrip
 
Регистрация: 21.01.2012
Сообщений: 241
По умолчанию

ну этот код просто скачивает в readBuffer html-код сайта) какой тут "низкий" уровень =) просто просит стороннюю сложную, непонятно как сделанную внутри, хреновину "ээ слыш скачай мне воон тот сайт в массив байтов и отдай его в readBuffer".

Вот такой же по сути код в дельфи, скачивает код сайта и кладет в файл, все средствами виндоуса, которые сами по себе соединяются по HTTP/HTTPS, возвращают код ошибки (200 если все ок, или там всякие 404, 3хх, 5хх и т.д.), скачивают код страницы/содержимое файла с сайта и остается только его использовать (например, сохранить в файл, как здесь).

Код:
uses
  Wininet;

{$R *.DFM}

function DownloadURL(AUrl, TargetFileName, ProxyName, ProxyBypass: PChar):Boolean;
const
  BUFFERSIZE = 4096;
var
  hSession: HINTERNET;
  hService: HINTERNET;
  lpBuffer: array[0..BufferSize + 1] of Byte;
  BufferLength: DWORD;
  dwBytesRead: DWORD;
  dwSizeOfRq, Reserved, dwByteToRead: DWORD;
  localFile: file;
  fsize: DWORD;
begin
  Result := False;
 
{ Initialize the Win32 Internet functions. }
 
  hSession := InternetOpen('MyApp', // Agent
    INTERNET_OPEN_TYPE_PRECONFIG, // dwAccessType
    nil, // lpszProxyName (optional)
    nil, // lpszProxyBypass (optional)
    0); // dwFlags
 
{
dwAccessType indicates the client machine's type of access to the
Internet,
with one of the following values:
 
INTERNET_OPEN_TYPE_DIRECT indicates client does not have to go through a
proxy server to access the Internet
INTERNET_OPEN_TYPE_PROXY indicates client must first pass through a proxy
server
to access the Internet.
INTERNET_OPEN_TYPE_PRECONFIG indicates client program should use whatever
value
is in the Registry to determine the type of
access.
 
dwFlags allows you to specify two options when the handle is created:
 
INTERNET_FLAG_OFFLINE indicates that all requests should be satisfied from
the cache.
INTERNET_FLAG_ASYNC indicates that requests should be satisfied using
asynchronous behavior.
}
 
// hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil,  0);
 
{ See if the session handle is valid }
 
if hSession = nil then
begin
  ShowMessage('Internet session initialization failed!');
  Exit;
end;
 
// Set options for the internet handle
// InternetSetOption(hSession, INTERNET_OPTION_CONNECT_TIMEOUT, @timeOutMS, sizeOf(timeOutMS));
 
{
InternetOpenUrl opens a handle to the Internet file using a URL.
The flags indicate that the file will always be read from the Internet
rather
than the cache.
}
 
hService := InternetOpenUrl(hSession,
  PChar(AUrl),
  nil,
  0,
  INTERNET_FLAG_DONT_CACHE or
  INTERNET_FLAG_PRAGMA_NOCACHE or
  INTERNET_FLAG_RELOAD,
  0);
 
{
INTERNET_FLAG_RELOAD: causes the program to reload the URL even if a copy
exists in the cache.
INTERNET_FLAG_DONT_CACHE: indicates not to cache the file retrieved.
INTERNET_FLAG_RAW_DATA: returns raw data if specified.
For FTP and Gopher, this data will be placed in the appropriate
_FIND_DATA structure.
INTERNET_FLAG_SECURE: is for conducting secure HTTP transactions via
either SSL or PCT.
INTERNET_FLAG_EXISTING_CONNECT: instructs WinInet to attempt to use an
existing connection to the remote server.
}
 
 
{ See if the session handle is valid }
if hSession = nil then
begin
  ShowMessage('Internet session initialization failed!');
  InternetCloseHandle(hService);
  Exit;
end;
 
HttpQueryInfo(hService, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER,
  @dwByteToRead,
  dwSizeOfRq, Reserved);
 
{ if dwByteToRead >= HTTP_STATUS_AMBIGUOUS then
begin
InternetCloseHandle(hService);
ShowMessage('STATUS CODE : ' + IntToStr(filesize));
Exit;
end; }
 
AssignFile(localFile, TargetFileName);
{$I-}
Rewrite(localFile, 1);
{$I+}
if IOResult <> 0 then
begin
  ShowMessage('Cannot create local file');
  InternetCloseHandle(hService);
  Exit;
end;
BufferLength := BUFFERSIZE;
 
{
These three variables will store the size of the file,
the size of the HttpQueryInfo content, and the number of bytes read in
total,
}
 
// determine the length of a file in bytes.
 
dwByteToRead := 0;
dwSizeOfRq := 4; // BufferLength
Reserved := 0;
 
{
With this call, an attempt is made to get the file's size.
If the attempt fails, the dwByteToRead variable is set to 0,
and no percentage or total size is displayed when the file is
downloaded.
}
 
if not HttpQueryInfo(hService,
  HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER,
  @dwByteToRead,
  dwSizeOfRq,
  Reserved) then dwByteToRead := 0;
FSize := 0;
BufferLength := BUFFERSIZE;
 
while (BufferLength > 0) do
begin
// Read data from the hService handle
  if not InternetReadFile(hService, @lpBuffer, BUFFERSIZE, BufferLength)
    then Break;
  if (BufferLength > 0) and (BufferLength <= BUFFERSIZE) then
    BlockWrite(localFile, lpBuffer, BufferLength);
 
  fsize := fsize + BufferLength;
// Application.ProcessMessages;
// Check the size of the remaining data. If it is zero, break.
  if BufferLength > 0 then Result := True;
end; {while}
 
CloseFile(localFile);
Result := True;
// Close the Internet handle that the application has opened.
InternetCloseHandle(hService);
end;
 
// Test it
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  DownloadURL('http://XYZ.html', 'c:\test.html', PChar('Proxyname'), PChar('Proxy Bypass'));
end;

Последний раз редактировалось blackstrip; Вчера в 10:18.
blackstrip вне форума Ответить с цитированием
Старый Вчера, 10:40   #3
Arigato
Высокая репутация
СуперМодератор
 
Аватар для Arigato
 
Регистрация: 27.07.2008
Сообщений: 15,866
По умолчанию

Цитата:
Сообщение от test2me Посмотреть сообщение
этот код делает запрос низкого уровня к какому-либо сайту.
Это не низкоуровневый запрос. Низкоуровневый запрос это когда вы сами формируете запрос по протоколу HTTP. А здесь все делается через CURL.
Arigato вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
интернет трафик водяной Помощь студентам 6 16.12.2010 23:57
Задача про интернет трафик Ya_tolko_uchus Помощь студентам 1 15.12.2010 17:00