mql4によるシンプルなPOST/GET HttpRequest - ページ 2

 

ありがとうございます。

私は自分のコンピュータ上でapacheサーバーを実行し、localhostを使用しています。だから、私はあなたが得たエラーメッセージを得ることはありませんが、代わりに私は "アクセス違反は 'Wininet.dll'の0x0000007Bに読んで "私は "HttpOpenRequestWを使用してエラーが出ています。

別のURLを試してみましたか?

 
私の固定コードでも?
 

はい、固定されたコードでもです。

これは私のコードです。

#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」を使うと、「Access violation read to 0x0000007B in 'Wininet.dll' 」という エラーメッセージが出ませんか?
 

また、前に言ったように、URLに何か問題があります(エラーコードは 嘘ではありません)。もちろん、私は"HttpOpenRequestA "ではなく、 "HttpOpenRequestW " を使用しています。

以下は、動作するコードです(trueを返し、エラーはありません)。

   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 "を使用して、"Access violation read to 0x0000007B in 'Wininet.dll'" というエラーが発生しました。

本当に残念なことになりました :-(.

 
coolex:

他のコンピュータでコードをテストしましたが、他のコンピュータでも、"HttpOpenRequestW "を使用して、"Access violation read to 0x0000007B in 'Wininet.dll'" というエラーが発生しました。

本当にがっかりしています :-(.


マイクロソフトでは

_In_  LPCTSTR *lplpszAcceptTypes

アクセス パラメータとして 宣言しています。string[]へのポインタが対応しているのかどうか、よくわかりません。string[]&を string&に 変更してみようと思います。

 

変更すると「'&' - reference cannot used」というエラーメッセージが表示されます。