egnew
Members-
Content Count
29 -
Joined
-
Last visited
Community Reputation
3 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Thanks -- I copied your code into my program and it worked. I traced the problem to the constructor of my TIndigoHttp type. I had recently added custom headers to match those chrome was sending when I was having an issue logging into a website. After resolving the logon issue, I forgot to remove the custom headers. The "No mapping for the Unicode character exists in the target multi-byte code page" error occurs when the two custom headers shown below are added to the request.. The error does not occur when I comment out either Add. I am not sure why there is a conflict. Google's encoding is "br". If you want to observe the issue, copy the custom header code below to immediately after you create lhttp. Comment out either Add and the mapping error will not occur. Do you have an idea why the headers cause the error? Thanks for your help, Sidney lhttp.CustHeaders.Clear; lHttp.CustHeaders.Add('Accept-Encoding','gzip, deflate, br, zstd'); lHttp.CustHeaders.Add('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36');
- 5 replies
-
- tnethttprequest
- delphi
-
(and 1 more)
Tagged with:
-
The status is 200 - OK as there is not a problem fetching the webpage. The exception occurs during the call to ContentAsString when TEncoding.GetString is executed. function TEncoding.GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): string; var Len: Integer; begin if (Length(Bytes) = 0) and (ByteCount <> 0) then raise EEncodingError.CreateRes(@SInvalidSourceArray); if ByteIndex < 0 then raise EEncodingError.CreateResFmt(@SByteIndexOutOfBounds, [ByteIndex]); if ByteCount < 0 then raise EEncodingError.CreateResFmt(@SInvalidCharCount, [ByteCount]); if (Length(Bytes) - ByteIndex) < ByteCount then raise EEncodingError.CreateResFmt(@SInvalidCharCount, [ByteCount]); Len := GetCharCount(Bytes, ByteIndex, ByteCount); if (ByteCount > 0) and (Len = 0) then raise EEncodingError.CreateRes(@SNoMappingForUnicodeCharacter); SetLength(Result, Len); GetChars(@Bytes[ByteIndex], ByteCount, PChar(Result), Len); end; The value for LEN is zero which causes the EEncodingError exception. As originally stated, I suspect the problem is related to encoding. The question is how to resolve the issue with native Http. I have no problem using Indy as it seems to handle the necessary details on its own. Thanks, Sidney
- 5 replies
-
- tnethttprequest
- delphi
-
(and 1 more)
Tagged with:
-
I am converting all my internet support code to use native TNetHttpClient and TNetHttpRequest components. I am getting the exception "No mapping for the Unicode character exists in the target multi-byte code page" for some web pages I am downloading using the function shown below. Here is an instance where the exception occur: GetText('https://www.google.com/index.html'); I assume this is an encoding issue. What is the best way to handle this to get my string result? function TIndigoHttp.GetText (const p_Url: String): String; var v_Response: IHTTPResponse; begin f_Error := ''; // Used by OnRequestError try v_Response := f_NetHTTPRequest.Get(p_Url); f_StatusCode := v_Response.StatusCode; f_StatusText := v_Response.StatusText; Result := v_Response.ContentAsString; except on E: Exception do with v_Response do begin begin Result := ''; f_StatusCode := -1*v_Response.StatusCode; f_StatusText := E.Message+' ['+v_Response.StatusText+']'; end; end; end; end;
- 5 replies
-
- tnethttprequest
- delphi
-
(and 1 more)
Tagged with:
-
I solved the problem by using Fiddler and found I was missing some parameters needed for the post. I added code to scan the HTML to make sure all required parameters were added to the post. Thanks for your suggestions.
- 6 replies
-
- native https
- logon
-
(and 2 more)
Tagged with:
-
Also, I tried setting CustHeaders in the NetHttpClient. I can also try that in the NetHTTPRequest but it didn't make a difference in the client. with f_NetHttpClient.CustHeaders do begin Clear; Add('Accept','*/*'); Add('AcceptEncoding','gzip,deflate,br,zstd'); Add('AcceptLanguage','en-US,en;q=0.9'); Add('ContentType','application/x-www-form-urlencoded; charset=UTF-8'); add('UserAgent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537..36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'); end; with f_NetHttpClient.CustHeaders do begin Clear; Add('Accept','*/*'); Add('AcceptEncoding','gzip,deflate,br,zstd'); Add('AcceptLanguage','en-US,en;q=0.9'); Add('ContentType','application/x-www-form-urlencoded; charset=UTF-8'); add('UserAgent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537..36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'); end; The documentation only listed a few parameters as available for custom headers but there were many more headers in the chrome debugger. Do limitations exist on what can be placed in the custom headers? Also, the documentation mentions setting MethodString in the request and using the Execute method. That didn't make sense to me when I needed to provide parameters to the POST. Do you think that could be part of the problem?
- 6 replies
-
- native https
- logon
-
(and 2 more)
Tagged with:
-
I have a working Indy version but I want to move everything over to the native components. It is no problem for me to install a sniffer. Am I using the correct steps in my procedures? Thanks, Sidney
- 6 replies
-
- native https
- logon
-
(and 2 more)
Tagged with:
-
I accidentally typed PUT as I am actually using POST. I have not tried a sniffer yet as I have not installed it on my new computer. I do have the information from accessing the site using Chrome's debugger and everything I am doing looks good., I will install the debugger if I can't get it working. Yes I have AllowCookies set to true. I have a unit which defines type TisNetHttp to handle all the details. Pertinent sections of code are shown below. In my main application I set a StringList named v_Params with the required values for the form I accessed using a GET. I then call the routines and check the downloaded file. myHttp.GetText(v_LogonUrl); // Fetches logon page myHttp.Post(v_LogonUrl,v_Params); // Send the form data myHttp.GetFile(v_PDFUrl,v_FileName); // Save the PDF // TYPE TisNetHttp = Class private { Private declarations } f_NetHTTPClient: TNetHTTPClient; f_NetHTTPRequest: TNetHTTPRequest; ... // CONSTRUCTOR f_NetHttpClient := TNetHttpClient.Create(nil); f_NetHttpClient.AllowCookies := True; f_NetHttpClient.HandleRedirects := True; f_NetHttpClient.OnAuthEvent := NetHttpClientAuthEvent; f_NetHttpRequest := TNetHttpRequest.Create(nil); f_NetHttpRequest.Client := f_NetHttpClient; f_NetHttpRequest.OnRequestCompleted := OnRequestCompleted; f_NetHttpRequest.OnRequestError := OnRequestError; procedure TisNetHttp.GetFile (const p_Url, p_FileName: String); // Similar to GetText below except content is saved to file ... function TisNetHttp.GetText (const p_Url: String): String; var v_Response: IHTTPResponse; begin f_Error := ''; // Used by OnRequestError try v_Response := f_NetHTTPRequest.Get(p_Url); f_StatusCode := v_Response.StatusCode; f_StatusText := v_Response.StatusText; Result := v_Response.ContentAsString; except on E: Exception do begin Result := ''; f_StatusCode := -1; f_StatusText := E.Message; end; end; end; procedure TisNetHttp.Post (const p_Url: String; var p_Strings: TStrings); var v_Response: IHTTPResponse; begin f_Error := ''; // Used by OnRequestError try v_Response := f_NetHTTPRequest.Post(p_Url,p_Strings); f_StatusCode := v_Response.StatusCode; f_StatusText := v_Response.StatusText; except on E: Exception do begin f_StatusCode := -1; f_StatusText := E.Message; end; end; end;
- 6 replies
-
- native https
- logon
-
(and 2 more)
Tagged with:
-
Hello: ' I have been using Indy to download PDF files containing images of data collected by two of our third party providers. It works fine with Indy but i am having a problem getting past the logon page when using TNetHttpClient and TNetHttpRequest. The logon page loads corrected with a GET and the HTML is correct. I then do a PUT with the username, password, and another required parameter. But when I try to download a file, the download is the content of the logon page, not the file I requested. What do I need to do to download from a website requiring a username and password with specific form requirements for obtaining a session? Thanks
- 6 replies
-
- native https
- logon
-
(and 2 more)
Tagged with:
-
I typecast the ContentStream as a TMemoryStream and SaveToFile worked perfectly. Thanks for your help.
-
I am using a TNetHttpRequest component to retrieve text from a secure website. I use the associated TNetHttpClient's OnAuthEvent to set the username and password. This allows me to retrieve text into a string using IHTTPResponse.ContentasString. I need to retrieve files from the same secured website. When I request the file using the same code, the IHTTPResponse.ContentStream seems to contain the requested file content since the IHTTPResponse.ContentLength appears to be correct. How can I save the content of IHTTPResponse.ContentStream to a file? Thanks
-
KodeZwerg. I had a solution using just System.TypInfo, which works for all simple types. try SetPropValue(p_Component,p_PropertyName,p_PropertyValue); except ... But your version is better as it allows me to set all properties. Example: SetPropertyValue(TControl(MyFDConnection.Params),'UserName','MyUserName'); Thank you very much.
-
How to fix W1055 Published Caused RTTI ($M+) Warning
egnew replied to egnew's topic in RTL and Delphi Object Pascal
I dynamically generate applications from text. This requires me to locate events by name. I am currently allowing either an event handler on a form or a built-in handler. The code I am using is this: function GetNotifyEvent (const p_MethodName: String; p_Form: TForm): TNotifyEvent; var v_Method: TMethod; begin v_Method.Data := Pointer(p_Form); v_Method.Code := p_Form.MethodAddress(p_MethodName); if v_Method.Code = nil then Result := BuiltInEvent(p_MethodName) else Result := TNotifyEvent(v_Method); end; Since I am using MethodAddress, I must publish methods I want to find by name. This is easy and is the approach I am using. I am open to other solutions. But my question is how to get rid of the warning from the compiler. -
How to fix W1055 Published Caused RTTI ($M+) Warning
egnew posted a topic in RTL and Delphi Object Pascal
I receive this warning when compiling a package: [dcc32 Warning] Indigo.EventHandlers.pas(11): W1055 PUBLISHED caused RTTI ($M+) to be added to type 'TisEventHandler' Documentation at https://docwiki.embarcadero.com/RADStudio/Sydney/en/W1055_Published_caused_RTTI_($M%2B)_to_be_added_to_type_'%s'_(Delphi)s says: The above description means nothing to me. How do I eliminate the warning from my package? Here is the code associated with the warning: type TisEventHandler = class published procedure isPrintScreenClick(Sender: TObject); end; Thanks -
Access Violation when Enabling TTimer in TComponent
egnew replied to egnew's topic in RTL and Delphi Object Pascal
Dalija Prasnikar: You are the best. I have not built any components in years and forgot to add the override. That was the issue. Thanks so much. -
Access Violation when Enabling TTimer in TComponent
egnew posted a topic in RTL and Delphi Object Pascal
I have a component in a Delphi package. The component contains a TTimer. When I manually create an instance of the Component, everything works fine. But when I drop the component on my form, everything works until the component tries to activate the timer. When the component attempts to start the timer with "FTimer.Enabled := True;", the access violation occurs. The following code from Vcl.ExtCtrls is called with Value=True but as soon as "if Value <> FEnabled" executes, the access violation occurs. procedure TTimer.SetEnabled(Value: Boolean); begin if Value <> FEnabled then begin FEnabled := Value; UpdateTimer; end; end Is this a bug or am I overlooking something? Thanks