WebRequest function

 

Hello,
I am using the WebRequest function in my code and encountering the following errors:

'WebRequest' - no one of the overloads can be applied to the function call

When I run the code, it gives an error, and I receive the following message:

'WebRequest' - no one of the overloads can be applied to the function call

What is the reason for this error?
Is the way the
WebRequest function is called correct?
If additional parameters need to be sent or changes need to be made in the way the function is called, what should I do?

Thank you in advance for your help.

string OpenAI_API_Key = "YOUR_API_KEY"; 
string Call_OpenAI_API(string prompt) 
{
   string result = "";
   string url = "https://api.openai.com/v1/completions"; 
   string headers = "Authorization: Bearer " + OpenAI_API_Key + "\r\nContent-Type: application/json\r\n";
   string body = "{\"model\":\"text-davinci-003\",\"prompt\":\"" + prompt + "\",\"max_tokens\":150}";
   // Send HTTP request
   char resultBuffer[];
   string error_message;
   int timeout = 5000; 
   int res = WebRequest("POST", url, headers, body, timeout, resultBuffer, error_message);
   if(res == -1)
   {
      Print("Error sending request: ", error_message);
      return "";
   }
   result = CharArrayToString(resultBuffer);
   return result;
}
 

Next time, please don't create a totally new topic just to "fix" the previous one in which you did not format code correctly. Your previous topic has been removed.

Also, your topic has been moved to the section: Expert Advisors and Automated Trading

Please consider which section is most appropriate when posting — https://www.mql5.com/en/forum/172166/page6#comment_49114893

 

Please refer to the WebRequest documentation. See version 2 of the function declaration ...

int  WebRequest(
   const string      method,           // HTTP method
   const string      url,              // URL
   const string      headers,          // headers 
   int               timeout,          // timeout
   const char        &data[],          // the array of the HTTP message body
   char              &result[],        // an array containing server response data
   string            &result_headers   // headers of server response
   );

Do you see the differences to your usage?

   string body = "{\"model\":\"text-davinci-003\",\"prompt\":\"" + prompt + "\",\"max_tokens\":150}";

   int res = WebRequest("POST", url, headers, body, timeout, resultBuffer, error_message);