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 |//+------------------------------------------------------------------+voidOnStart()
{
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");
}
elseprintf("Ошибка в FileOpen. Код ошибки =",GetLastError());
}
elseprintf("Ошибка загрузки '%s', код %d",url,res);
}
}
//+------------------------------------------------------------------+
as soon as the second header is added, authorization stops working
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 - это индексы в наборе символов Unicode. Они являются 16-разрядными значениями, которые можно преобразовывать в целые числа и с которыми можно манипулировать целочисленными операциями, такими как сложение и вычитание. Любой одиночный символ, заключенный в одинарные кавычки, или шестнадцатеричный ASCII-код...
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:
Для использования функции WebRequest() следует добавить адреса серверов в список разрешенных URL во вкладке "Советники" окна "Настройки". Порт сервера выбирается автоматически на основе указанного протокола - 80 для "http://" и 443 для "https://". Функция WebRequest() является синхронной, это означает, что она приостанавливает выполнение...
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 ))
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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
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
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
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:
Apparently, the service is paid for.
Up to 10,000 characters a month can be voiced for free.
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:
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 ))
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
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
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