使用mql4的简单POST/GET HttpRequest - 页 2 1234 新评论 [删除] 2014.03.19 19:52 #11 非常感谢! 我在我的电脑上运行一个apache服务器,使用localhost。这就是为什么我没有得到你的错误信息,而是得到 "Access violation read to 0x0000007B in 'Wininet.dll'" i using "HttpOpenRequestW" 的错误。 你试过其他的网址吗? qjol 2014.03.19 19:55 #12 即使有我的固定代码? [删除] 2014.03.19 19:59 #13 是的,即使有固定的代码。 这是我的代码。 #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。 qjol 2014.03.19 20:12 #14 就像我之前说的那样,代码工作正常,但是URL有问题。 [删除] 2014.03.19 20:17 #15 嗯,我不知道"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); [删除] 2014.03.19 20:37 #16 @qjol:如果你在最后一段代码中 使用"HttpOpenRequestW ",你不会得到错误信息"在'Wininet.dll'中读取到0x0000007B的访问违规 " 吗? qjol 2014.03.19 20:57 #17 正如我之前所说,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); [删除] 2014.03.20 06:25 #18 我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规" 。 这真是越来越令人失望了 :-(. Ex Ovo Omnia 2014.03.20 07:43 #19 coolex:我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规" 。 这真是越来越让人失望了 :-(. 微软声明 _In_ LPCTSTR *lplpszAcceptTypes 为访问 参数。我不确定指向string[]的指针是否与之兼容。我会尝试把string[]& 改为string&。 [删除] 2014.03.20 07:56 #20 如果我进行修改,我收到错误信息"'&'--不能使用引用"。 1234 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
非常感谢!
我在我的电脑上运行一个apache服务器,使用localhost。这就是为什么我没有得到你的错误信息,而是得到 "Access violation read to 0x0000007B in 'Wininet.dll'" i using "HttpOpenRequestW" 的错误。
你试过其他的网址吗?
是的,即使有固定的代码。
这是我的代码。
有趣的是,如果我把 "HttpOpenRequestW "改为 "HttpOpenRequestA",我也会收到错误12005。
嗯,我不知道"HttpOpenRequestW "或 "HttpOpenRequestA "是否正确。现在我使用 "HttpOpenRequestA",否则就会出现错误信息 "Access violation read to 0x0000007B in 'Wininet.dll'"。
关于URL,我尝试了很多不同的其他URL,甚至是你的例子中的那个(把POST改为GET等)。
正如我之前所说,URL出了问题(错误代码 没有说谎),当然我使用的是"HttpOpenRequestW"而不是 "HttpOpenRequestA"
这里是一个工作代码(返回真,没有错误)。
我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规" 。
这真是越来越令人失望了 :-(.
我在其他电脑上测试了代码,即使在其他电脑上,我仍然得到错误:"使用 "HttpOpenRequestW "读取'Wininet.dll'中的0x0000007B的访问违规" 。
这真是越来越让人失望了 :-(.
微软声明
为访问 参数。我不确定指向string[]的指针是否与之兼容。我会尝试把string[]& 改为string&。
如果我进行修改,我收到错误信息"'&'--不能使用引用"。