mql4 ile basit POST/GET HttpRequest - sayfa 2

 

çok teşekkürler!

Bilgisayarımda bir apache sunucusu çalıştırıyorum ve localhost kullanıyorum. Bu yüzden aldığınız hata mesajını almıyorum ama bunun yerine "HttpOpenRequestW" kullanarak "Wininet.dll'de 0x0000007B'ye erişim ihlali okundu" hatası alıyorum.

Başka bir url denediniz mi?

 
sabit kodumla bile mi?
 

Evet, sabit kodla bile.

Bu benim kodum:

 #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 ;
}

İlginçtir ki, "HttpOpenRequestW" öğesini "HttpOpenRequestA" olarak değiştirirsem 12005 hatasını da alıyorum.

 
yani daha önce söylediğim gibi kod iyi çalışıyor ama URL ile ilgili bir sorun var
 

"HttpOpenRequestW" veya "HttpOpenRequestA" doğru mu bilmiyorum. Şimdi "HttpOpenRequestA" kullanıyorum, aksi takdirde "Erişim ihlali 'Wininet.dll'de 0x0000007B'ye okundu" hata mesajını alıyorum .

URL'lerle ilgili olarak, pek çok farklı URL denedim, örneğinizdeki URL bile (POST, GET olarak değiştirildi vb.):

   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: Son kodda " HttpOpenRequestW" kullanırsanız "Erişim ihlali 'Wininet.dll'de 0x0000007B'ye okundu" hata mesajını almıyor musunuz?
 

daha önce de söylediğim gibi URL'de bir sorun var ( hata kodları yalan söylemez) ve tabii ki "HttpOpenRequest A " değil "HttpOpenRequest W " kullanıyorum

işte çalışan bir kod (doğru olarak döner ve hata yoktur):

   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);
 

Kodu diğer bilgisayarlarda test ettim ve hatta diğer bilgisayarlarda bile şu hatayı alıyorum: "HttpOpenRequest W " kullanarak "'Wininet.dll'de 0x0000007B'ye erişim ihlali okundu".

Gerçekten hayal kırıklığı oluyor :-(.

 
coolex :

Kodu diğer bilgisayarlarda test ettim ve hatta diğer bilgisayarlarda bile şu hatayı alıyorum: "HttpOpenRequest W " kullanarak "'Wininet.dll'de 0x0000007B'ye erişim ihlali okundu".

Gerçekten hayal kırıklığı oluyor :-(.


Microsoft bildiriyor

_In_  LPCTSTR *lplpszAcceptTypes

erişim parametresi için . [] dizesine bir işaretçinin onunla uyumlu olup olmadığından emin değilim. []& dizesini string& olarak değiştirmeyi denerdim.

 

Değişikliği yaparsam "'&' - başvuru kullanılamıyor" hata mesajını alıyorum.

Neden: