mql4를 사용한 간단한 POST/GET HttpRequest - 페이지 2

 

많은 감사합니다!

내 컴퓨터에서 Apache 서버를 실행 중이고 localhost를 사용합니다. 그렇기 때문에 오류 메시지가 표시되지 않지만 대신 "HttpOpenRequestW"를 사용하여 "'Wininet.dll'의 0x0000007B에 대한 액세스 위반 읽기" 오류가 발생합니다.

다른 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"를 사용합니다. 그렇지 않으면 "'Wininet.dll'의 0x0000007B에 대한 액세스 위반 읽기"라는 오류 메시지가 나타 납니다.

URL과 관련하여 나는 당신의 예(POST를 GET 등으로 변경)의 URL을 포함하여 다른 많은 URL을 시도했습니다.

   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에 문제가 있기 전에 다시 말했듯이( 오류 코드 는 거짓말을 하지 않음) 물론 "HttpOpenRequest A "가 아닌 "HttpOpenRequest W " 를 사용하고 있습니다.

다음은 작동하는 코드입니다(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);
 

다른 컴퓨터에서 코드를 테스트했는데 다른 컴퓨터에서도 "HttpOpenRequest W "를 사용하여 "액세스 위반이 'Wininet.dll'에서 0x0000007B로 읽혔습니다."라는 오류가 계속 발생합니다.

정말 실망스럽네요 :-(.

 
coolex :

다른 컴퓨터에서 코드를 테스트했는데 다른 컴퓨터에서도 "HttpOpenRequest W "를 사용하여 "액세스 위반이 'Wininet.dll'에서 0x0000007B로 읽혔습니다."라는 오류가 계속 발생합니다.

정말 실망스럽네요 :-(.


마이크로소프트는 선언한다

_In_  LPCTSTR *lplpszAcceptTypes

액세스 매개변수 의 경우 . string[]에 대한 포인터가 호환되는지 확실하지 않습니다. string[]&string& 로 변경하려고 합니다.

 

변경하면 "'&' - 참조를 사용할 수 없습니다"라는 오류 메시지가 나타납니다.