Home > Back-end >  Very strange questions, in XE7 DLL project, use idhttp get method returns too much data, will collap
Very strange questions, in XE7 DLL project, use idhttp get method returns too much data, will collap

Time:09-18

Extern "C" __declspec (dllexport) char * __stdcall test url (char *)//export function
{
TIdSSLIOHandlerSocketOpenSSL * IdSSLIOHandlerSocketOpenSSL1=new TIdSSLIOHandlerSocketOpenSSL (NULL);

TIdHTTP * HTTP=new TIdHTTP (NULL);

HTTP - & gt; IOHandler=IdSSLIOHandlerSocketOpenSSL1;
IdSSLIOHandlerSocketOpenSSL1 - & gt; SSLOptions - & gt; Method=sslvSSLv2;
IdSSLIOHandlerSocketOpenSSL1 - & gt; SSLOptions - & gt; Mode=sslmBoth;
IdSSLIOHandlerSocketOpenSSL1 - & gt; ReadTimeout=10000;
HTTP - & gt; ReadTimeout=10000;

AnsiString HTML;
Try {
HTML=HTTP - & gt; Get (url);//to perform here, if the data returned is not a lot, no problem, if the data returned a lot of, will collapse, seems even can not capture the catch, and then jump out to a memory error, I was written in xe7 DLL, BCB6 calls,
Return HTML. C_str ();
} the catch (Exception & amp; E) {
Return HTML. C_str ();
}
}

CodePudding user response:

AnsiString HTML;
Stack variables to the static or global variables to try,

CodePudding user response:

May be Get (url); Can't deal with too much data, method usually used TIdCustomHTTP. Get (string, TIdStream);
Such as:
TStringStream * StringStream1=new TStringStream (" ", TEncoding: : Default, true);
IdHTTP1 - & gt; Get (url, StringStream1);
StringStream1 - & gt; The Position=0;
StringStream1 - & gt; The Position=0;
AnsiString HTML=StringStream1 - & gt; DataString. The Trim ();//DataString is web content

The code above, however, there are a few problems haven't solved, such as web pages are utf8 will be garbled, network access when something goes wrong, there is no deal with, I have a special function, good post,
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
UnicodeString __fastcall TForm1: : GetUrlText (UnicodeString strUrl)
{
TIdSSLIOHandlerSocketOpenSSL * IdSSLIOHandlerSocketOpenSSL1=new TIdSSLIOHandlerSocketOpenSSL (this);
IdSSLIOHandlerSocketOpenSSL1 - & gt; SSLOptions - & gt; Method=sslvSSLv3;
IdSSLIOHandlerSocketOpenSSL1 - & gt; SSLOptions - & gt; Mode=sslmClient;
//an executable program should put under ssleay32. DLL and libeay32. Two dynamic library DLL, or open the HTTPS protocol web complains,
//the OpenSSL Indy version download http://indy.fulgan.com/SSL/
//the latest 32-bit openssl 1.0.2 o - i386 - win32. Zip
//the latest openssl - 64 1.0.2 o - x64_86 - win64. Zip

TIdHTTP * IdHTTP2=new TIdHTTP (this);

IdHTTP2 - & gt; ConnectTimeout=6000;
IdHTTP2 - & gt; ReadTimeout=6000;

IdHTTP2 - & gt; Request - & gt; The Accept="text/HTML, application/XHTML + XML, application/XML. Q=0.9 */*; Q=0.8 ";
IdHTTP2 - & gt; Request - & gt; UserAgent="Mozilla/5.0 (Windows NT 6.0; The rv: 5.0) Gecko/20100101 Firefox/5.0 ";
IdHTTP2 - & gt; Request - & gt; AcceptCharSet="GB2312, utf-8; Q=0.7 *; Q=0.7 ";
IdHTTP2 - & gt; Request - & gt; AcceptLanguage="useful - cn, useful; Q=0.8, en - us; Q=0.5, en. Q=0.3 ";
IdHTTP2 - & gt; Request - & gt; The Connection="keep - the alive";
IdHTTP2 - & gt; Request - & gt; ContentType="application/x - WWW - form - urlencoded";
IdHTTP2 - & gt; ProtocolVersion=pv1_1;
IdHTTP2 - & gt; ConnectTimeout=6000;
IdHTTP2 - & gt; ReadTimeout=6000;
IdHTTP2 - & gt; IOHandler=IdSSLIOHandlerSocketOpenSSL1;
//IdSSLIOHandlerSocketOpenSSL1 TIdHTTP seemed to need be generated inside, is not new and Settings can also be used,

TMemoryStream * StreamMSG=new TMemoryStream ();
UnicodeString responsestr;
Try
{
IdHTTP2 - & gt; Get (strUrl. The Trim (), StreamMSG);
StreamMSG - & gt; The Position=0;
If (IdHTTP2 - & gt; ResponseCode==200)
{
StreamMSG - & gt; The Position=0;
((char *) StreamMSG - & gt; The Memory) [(int) StreamMSG - & gt; Size]=0;
Responsestr=UnicodeString ((char *) StreamMSG - & gt; The Memory);
If (IdHTTP2 - & gt; The Response - & gt; CharSet. LowerCase ()=="utf-8")
{
_di_IIdTextEncoding TextEncoding1=CharsetToEncoding (" utf-8 ");
Responsestr=ReadStringFromStream (StreamMSG, 1, TextEncoding1);
//or responsestr=ReadStringFromStream (StreamMSG, 1, IndyTextEncoding (TEncoding: : UTF8));
}
}
The else responsestr=L "page not the normal response,";
}
The catch (const EIdHTTPProtocolException & amp; E)
{
//HTTP error
//E.E rrorCode contains the ResponseCode
//E.M essage contains the ResponseText
//E.E rrorMessage contains the content of the error body, if any)
UnicodeString xingxi;
Error xingxi="HTTP: \ r \ n";
Xingxi +="ErrorCode:";
Xingxi +=E.E rrorCode;
Xingxi +="\ r \ n";
Xingxi +="Message:";
Xingxi +=E.M essage.
Xingxi +="\ r \ n";
Xingxi +="ErrorMessage:";
Xingxi +=E.E rrorMessage;
ShowMessage (xingxi);
}
The catch (const EIdSocketError & amp; E)
{
//Socket error
//E.L astError contains the socket error code
//E.M essage contains the socket error message
If (E.L astError==Id_WSAECONNREFUSED)
ShowMessage (L "Your connection is refused");
The else
ShowMessage (E.M essage);
}
The catch (const EIdException & amp; E)
{
//any other Indy error
ShowMessage (" Error: "+ E.M essage);
}
The catch (Exception & amp; E)
{
//any other non - Indy error
ShowMessage (" Error: "+ E.M essage);
}
The delete StreamMSG;
The delete IdHTTP2;
Return responsestr;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

Just in the DLL will appear this problem, in the form in the application,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related