使用mql4的简单POST/GET HttpRequest - 页 2

 

非常感谢!

我在我的电脑上运行一个apache服务器,使用localhost。这就是为什么我没有得到你的错误信息,而是得到 "Access violation read to 0x0000007B in 'Wininet.dll'" i using "HttpOpenRequestW" 的错误。

你试过其他的网址吗?

 
即使有我的固定代码?
 

是的,即使有固定的代码。

这是我的代码。

#import  "Wininet.dll"
   int InternetOpenW(string, int, string, string, int);
   int InternetConnectW(int, string, int, string, string, int, int, int); 
   int InternetOpenUrlW(int, string, string, int, int, int);
   int InternetReadFile(int, string, int, int& OneInt[]);
   int InternetCloseHandle(int); 
   int HttpOpenRequestW(int, string, string, string, string, string& AcceptTypes[], int, int);
   bool HttpSendRequestW(int, string, int, string, int);
#import
#import "kernel32.dll"
int GetLastError(void);
#import
 
int OnInit()
{
   //----
   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   string acceptTypes[1] = {"*/*"};

   int HttpOpen = InternetOpenW("HTTP_Client_Sample", 1, "", "", 0);  
   int HttpConnect = InternetConnectW(HttpOpen, "http://localhost/tradex", 7777, "", "", 3, 0, 1);
   int HttpRequest = HttpOpenRequestW(HttpConnect, "POST", "/index.php", "HTTP/1.1", "", acceptTypes, 0, 1);
   bool result = HttpSendRequestW(HttpRequest, headers, StringLen(headers), data, StringLen(data));
   Alert ("Last MSDN Error =: ", kernel32::GetLastError());
   
   int read[1]; // not used
   Print("This is the POST result: ", result);
   if (HttpOpen > 0)
   InternetCloseHandle(HttpOpen);
   if (HttpRequest > 0)
   InternetCloseHandle(HttpRequest);
   
   return;
}

有趣的是,如果我把 "HttpOpenRequestW "改为 "HttpOpenRequestA",我也会收到错误12005

 
就像我之前说的那样,代码工作正常,但是URL有问题。
 

嗯,我不知道"HttpOpenRequestW "或 "HttpOpenRequestA "是否正确。现在我使用 "HttpOpenRequestA",否则就会出现错误信息 "Access violation read to 0x0000007B in 'Wininet.dll'"。

关于URL,我尝试了很多不同的其他URL,甚至是你的例子中的那个(把POST改为GET等)。

   int HttpConnect = InternetConnectW(HttpOpen, "http://www.forexfactory.com", 7777, "", "", 3, 0, 1);
   int HttpRequest = HttpOpenRequestA(HttpConnect, "GET", "/ff_calendar_thisweek.xml", "HTTP/1.1", "", acceptTypes, 0, 1);
 
@qjol:如果你在最后一段代码中 使用"HttpOpenRequestW ",你不会得到错误信息"在'Wininet.dll'中读取到0x0000007B的访问违规 "
 

正如我之前所说,URL出了问题(错误代码 没有说谎),当然我使用的是"HttpOpenRequestW"而不是 "HttpOpenRequestA"

这里是一个工作代码(返回真,没有错误)。

   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   string acceptTypes[1] = {""};

   int HttpOpen = InternetOpenW(" ", 0, " ", "", 0);  
   int HttpConnect = InternetConnectW(HttpOpen, "www.forexfactory.com", 80, "", "", 3, 0, 0);
   int HttpRequest = HttpOpenRequestW(HttpConnect, "GET", "ff_calendar_thisweek.xml", "", "", acceptTypes, 0, 0);   
   bool result = HttpSendRequestW(HttpRequest, headers, StringLen(headers), data, StringLen(data));
   Alert ("Last MSDN Error =: ", kernel32::GetLastError());
   int read[1];
   Print("This is the POST result: ", result);
   InternetCloseHandle(HttpOpen);
   InternetCloseHandle(HttpRequest);
 

我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规"

这真是越来越令人失望了 :-(.

 
coolex:

我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规"

这真是越来越让人失望了 :-(.


微软声明

_In_  LPCTSTR *lplpszAcceptTypes

访问 参数。我不确定指向string[]的指针是否与之兼容。我会尝试把string[]& 改为string&。

 

如果我进行修改,我收到错误信息"'&'--不能使用引用"。

原因: