and again dll and market - page 20

 
Alexsandr San:

Here on this site - I uploaded a text file - and got a .wav file

how to organise it automatically is the question!?https://audio.online-convert.com/convert-to-wav

English only.

Your example is good, but on this site there is no authorization, i.e. no need to specify multiple headers in the request, and hence no need to understand the syntax of such an entry.

Maybe, maybe I'm wrong, but I can't find any other explanation for hanging in case of one header and authorization error in case of another header. Here is the code with two headers

//+------------------------------------------------------------------+
//|                                                   WebRequest.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string cookie=NULL,headers;
   char   post[],result[];
   char cost_char_data[];
   string  result_headers;
   
   ResetLastError();
   ArrayFree(result);
  // headers = "Authorization: Basic YXBpa2V5OkdSMWJiM3pWTXM5ZmNOS0w2cEE5LTV6ajlwdFdsaUN1NmVoOW91cFVucFpC/r/n";
   headers = "Authorization: Basic YXBpa2V5OkdSMWJiM3pWTXM5ZmNOS0w2cEE5LTV6ajlwdFdsaUN1NmVoOW91cFVucFpC";
//   headers = headers + "Accept: audio/wav";
   headers = headers + "/r/nAccept: audio/wav/r/n";
  // headers = headers + "Accept: audio/wav/r/n";
 
   string url="https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/9886a3ce-5734-455f-8f78-7a56381da686/v1/synthesize?text=TEST";
               
   int res = WebRequest("GET",url,headers,1000,cost_char_data,result,result_headers);

   if(res==-1)
     {
      printf("Ошибка в WebRequest. Код ошибки  =",GetLastError());
      //--- возможно, URL отсутствует в списке, выводим сообщение о необходимости его добавления
      MessageBox("Необходимо добавить адрес '"+url+"' в список разрешенных URL во вкладке 'Советники'","Ошибка",MB_ICONINFORMATION);
     }
   else
     {
      if(res==200)
        {
         //--- успешная загрузка
         printf("Файл успешно загружен, размер %d байт.",ArraySize(result));
         printf("Заголовки сервера: %s",result_headers);
         //--- сохраняем данные в файл
         int filehandle=FileOpen("testmql5.ogg",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,result,0,WHOLE_ARRAY);
            //--- закрываем файл
            FileClose(filehandle);
            printf("FileClose");
            
           }
         else
            printf("Ошибка в FileOpen. Код ошибки =",GetLastError());
        }
      else
         printf("Ошибка загрузки '%s', код %d",url,res);
     }
  }
//+------------------------------------------------------------------+

as soon as the second header is added, authorization stops working

2020.06.01 12:46:45.044 Webrequest4Voice (EURAUD,H1) Upload error 'https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/9886a3ce-5734-455f-8f78-7a56381da686/v1/synthesize?text=TEST', code 401

With one header the authorization works, but the stream is driven to the file with extra characters that make it impossible to play the audio file

 
Nikolai Karetnikov:

There's another problem. As we say among experts: "there's some kind of malfunction" )).

Just above I wrote in detail how WebRequest freezes but receives a stream nevertheless. The stream gets to the file and turns out to be broken. Perhaps I'm putting it into file incorrectly, but most likely the char array gets filled with extraneous information at the moment of deadlock.

This is what we should deal with now

read (!!!) how http transfers data... something about chunked :-)

The first line in the content is service data (length if memory serves), and only then the binary file data

 
perhaps the /r/n line feed characters should be added to the headers differently, maybe something else, like a space at the beginning or at the end of the header. Without a working example it's hard to figure it out
Документация по MQL5: Основы языка / Типы данных / Целые типы / Символьные константы
Документация по MQL5: Основы языка / Типы данных / Целые типы / Символьные константы
  • www.mql5.com
Символы, как элемент строки, в MQL5 - это индексы в наборе символов Unicode. Они являются 16-разрядными значениями, которые можно преобразовывать в целые числа и с которыми можно манипулировать целочисленными операциями, такими как сложение и вычитание. Любой одиночный символ, заключенный в одинарные кавычки, или шестнадцатеричный ASCII-код...
 
Nikolai Karetnikov:

There's another problem. As we say among experts: "there's some kind of malfunction" )).

Just the WebRequest function works in a specific way and is internally restricted for such use. "

I've been testing the script and I'm left with the question: where did the key come from?

Had a chat with their agent. The first question he asked was:

Ok no worries, Are you using a free or paid plan?

And another:

Hello, thank you for contacting IBM Cloud. For technical assistance we would recommend to check all the available docs at your disposal as we are mainly a self service platform.

But, gave links where you can talk more about the topic of interest:https://www.ibm.com/watson at the bottom there is an icon of chat Let's talk!

Further, another link he gave me opened this page:


Документация по MQL5: Сетевые функции / WebRequest
Документация по MQL5: Сетевые функции / WebRequest
  • www.mql5.com
Для использования функции WebRequest() следует добавить адреса серверов в список разрешенных URL во вкладке "Советники" окна "Настройки". Порт сервера выбирается автоматически на основе указанного протокола - 80 для "http://" и 443 для "https://". Функция WebRequest() является синхронной, это означает, что она приостанавливает выполнение...
 

Apparently, the service is paid for.

Up to 10,000 characters a month can be voiced for free.

 
Реter Konow:

This falls into point 3 - "Eitherthe WebRequest function works in a specific way and is internally restricted for such use. "

I was testing the script and was left with the question: WHERE does the key come from?

Had a chat with their agent. The first question he asked was:

Ok no worries, Are you using a free or paid plan?

And another:

Hello, thank you for contacting IBM Cloud. For technical assistance we would recommend to check all the available docs at your disposal as we are mainly a self service platform.

But, gave links where you can talk more about the topic of interest:https://www.ibm.com/watson at the bottom there is an icon of chat Let's talk!

Further, another link he gave me opened this page:


Maxim Kuznetsov:

read (!!!) what kind of data http gives away...something about chunked :-)

in the content, first line is the service data (length if memory serves), and only then the binary file data

Thank you!

I read some info, found error in my code, fixed it, WebRequest stopped hanging and gets stream, but I see following info in file anyway

There must be another "something wrong" somewhere ))

 
Look at the picture. Free plan up to 10,000 characters per month.
 
Maxim Kuznetsov:

read (!!!) how http gives data...something about chunked :-)

the first line of content contains service data (length, if memory serves me correctly), and only then the binary file data

i.e. i now understand that in the retrievable stream


00000089 is service data, but I don't understand how to make it ignore

 
Реter Konow:
Look at the picture. The free plan is up to 10,000 characters a month.

Yes, yes you are right. I've written about it here before too

и снова dll и маркет
и снова dll и маркет
  • 2020.05.31
  • www.mql5.com
День добрый! Правило №1 dll на Маркете запрещен...
 
Реter Konow:
Look at the picture. Free plan up to 10,000 characters per month.

when you register on their website and follow the prompts, a page appears at one point wherethe apikey is listed

Reason: