0

Может кто-нибудь мне помочь и сказать почему возвращается пустая страница?
Вроде бы все делаю правильно, код рабочий, ответ приходит 200 ок, а при считывании выходит страница, которая грузится по дефолту если данные не отправлены.

    wstring wurl = L"http://www.preciosa.com.ua/rus/obrazec-numeracii-preciosa.html";
    wstring form_params = L"q="+ParseStringForQuery(item[L"article"]);
    form_params+=L"&but_search=%C8%F1%EA%E0%F2%FC";
    LPCWSTR post_headers = 
        L"Content-Type: application/x-www-form-urlencoded\n\
         Cookie: b=b\n\
         Connection: Keep-Alive\n\
         Accept-Encoding: gzip, deflate\n\
         User-Agent: Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.12\n\
         Host: www.preciosa.com.ua\n\
         Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, /\\*;q=0.1\n\
         Accept-Language: ru,uk;q=0.9,ru-RU;q=0.8,en;q=0.7\n\
         Accept-Encoding: gzip, deflate\n\
         Referer: http://www.preciosa.com.ua/rus/obrazec-numeracii-preciosa.html\n\
         Cookie: b=b\n\
         Connection: Keep-Alive\n\
         Content-Length: 68\n\
         Content-Type: application/x-www-form-urlencoded\n\0";

    LPCWSTR accept_types[]={_T("text/*"), NULL};
                                    /*{
        L"text/html",
        L"application/xml;q=0.9",
        L"application/xhtml+xml",
        L"image/png",
        L"image/jpeg",
        L"image/gif",
        L'\0'};*/
        /*
        POST /rus/katalog.html HTTP/1.1
        User-Agent: Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.12
        Host: www.preciosa.com.ua
        Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, /\\*;q=0.1
        Accept-Language: ru,uk;q=0.9,ru-RU;q=0.8,en;q=0.7
        Accept-Encoding: gzip, deflate
        Referer: http://www.preciosa.com.ua/rus/obrazec-numeracii-preciosa.html
        Cookie: b=b
        Connection: Keep-Alive
        Content-Length: 68
        Content-Type: application/x-www-form-urlencoded
        Имя Значение
        q   FR 5345/00/008
        but_search  Искать
        */
   DWORD error_code=0;

   HINTERNET hSession = InternetOpen(L"Opera 12",
      INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

     error_code = GetLastError();

   HINTERNET hConnect = InternetConnect(hSession, L"www.preciosa.com.ua",
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);

    error_code = GetLastError();

   HINTERNET hRequest = HttpOpenRequest(hConnect, L"POST",
      _T("/rus/katalog.html"), L"HTTP/1.1" , L"http://www.preciosa.com.ua/rus/obrazec-numeracii-preciosa.html",
      accept_types, INTERNET_FLAG_KEEP_CONNECTION, 1);

        error_code = GetLastError(); //122 here
   //ERROR_INSUFFICIENT_BUFFER ???? WTF???

   if(!HttpSendRequest( hRequest, post_headers, lstrlenW(post_headers), &form_params.at(0),
       form_params.length() ))
       error_code = GetLastError();

   char buffer[65536];
   DWORD bufferLength = 65536;
   DWORD index = 0;
   if(!HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &bufferLength,NULL))
       error_code = GetLastError();
   string temp(buffer,500);
   std::remove(temp.begin(), temp.end(), '\0'); 
   error_code = GetLastError();

    string page;
    page.resize(0xFFFF);
    DWORD bytes_read=1;
    DWORD temp_bytes =0;
    while(bytes_read) {

        InternetReadFile(hRequest, &page.at(temp_bytes), 0xFFFF, &bytes_read);
        temp_bytes += bytes_read;
        //InternetReadFileExW(hRequest, &InternetBuffersOut, NULL, NULL);
        //code = GetLastError();
    }
    std::remove(begin(page),end(page),'\0');
    wstring page_unicode_content;
   // close any valid internet-handles
    {
        string convertable = page;
        wstring temp;
        if(convertable.length()==0)
            temp =  L"";
        else
            temp.resize(convertable.length());
        MultiByteToWideChar(CP_UTF8, NULL, convertable.c_str(), convertable.length(), &temp.at(0), convertable.length());
        page_unicode_content = temp;
    }

    InternetCloseHandle(hSession);

1 ответ 1

0

Снифер в руки и смотреть что отправляет сервер браузеру а что вашей софтине, скорее всего какие то куки ставятся или сессия пишется.

4
  • Как думаете, Wireshark подойдет для этих целей?
    – PaulD
    7 янв 2013 в 13:42
  • да чем нравится тем и снифь, тут дело вкуса, что касается вами названной программы я ей не работал так что не скажу.
    – Rsecomua
    7 янв 2013 в 14:32
  • не сниффит оно что-то ничего. Dead-end какой-то
    – PaulD
    7 янв 2013 в 16:10
  • от браузера пакеты ловит, от приложения не хочет почему-то...
    – PaulD
    7 янв 2013 в 16:10

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.