Recent

Author Topic: [SOLVED] TIDHTTP can't read file on server  (Read 3919 times)

yawa16

  • New Member
  • *
  • Posts: 10
[SOLVED] TIDHTTP can't read file on server
« on: June 30, 2014, 10:23:56 pm »
Hi,

My application uses a TIdHTTP component to read the contents of a file on a server. This file contains the newest version of the application, by comparing it to the version of the application it decides to prompt the user a dialog saying there's a newer version available or not. This works perfectly on the server I use now, but I recently got another (free) server and now it doesn't work any more. I have checked the filepath, it is 100% correct. Entering the exact same path in my browser gives the desired version number, but trying to read the same file with IdHTTP.Get(file) does not work. It did however on the previous server. I contacted the helpdesk of the webhost, but they could not think of any solution. There are no hotlink protections active. What could be the cause or in what way could I get more information on the error so the helpdesk may be able to help me?
« Last Edit: July 01, 2014, 11:03:26 am by yawa16 »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TIDHTTP can't read file on server
« Reply #1 on: June 30, 2014, 10:36:49 pm »
1) give us something to work with a dry description of what you see lets everything to the imagination. How about a small sample showing how idHTTP is used.
2) If there is no sample application or there is no time to create one then a link to the file you have problemswith would be required so we can do our own tests, make sure that the link you provide is for a test file not anything proprietary that shouldn't be shared.

3) I had problems like that with my spider application (which sadly was only in the disk that crashed on me a couple of months back, haven't found the time to rewrite it yet) some sites would return a 403 or 404 can't remember exactly after a days searching I found out that the request.userAgent must be something unique do not use any generic value some servers forbid access to those agents for security reasons (they where used from various attack bots).
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: TIDHTTP can't read file on server
« Reply #2 on: July 01, 2014, 01:25:11 am »
Yes, it's difficult indeed to provide any help without any more pieces of information...

You could make a full exchange log with the TIdLogFile class/component. Or look at the error returned by Indy (you can use the exceptions class for that).


Anyway, a few more things to check:

1/  Be sure to allow redirection, with something like (you may also fill the appropriate fields in you use a TIdComponent):
Code: [Select]
...
  MyIdHTTP.HandleRedirects:=True;
  MyIdHTTP.RedirectMaximum:=10;   // (Generally, 3 is quite enough)
...

2/  If redirection is used, be sure that the HTTPS protocol is not required by the server. It's becoming more and more frequent that servers redirect automatically their clients to their encrypted version. If so, you'll have to add the 2 openssl .dll files.

3/  And finally, as an addition to Taazz's point 3, be sure to modify the by-default user agent of the Indy http component.
 The by-default value is:
Code: [Select]
User-Agent: Mozilla/3.0 (compatible; Indy Library)
The problem is that this value is blacklisted by several domains/servers. AFAIK, the reason why is that Indy has been used in the past by malware programs (I'm not completely sure about the reason).

You can make a test with this Mozilla  value for instance:
Code: [Select]
  MyIdHTTP.Request.UserAgent:='Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0';    // Some web sites don't like the old by-default one (i.e. malware)

yawa16

  • New Member
  • *
  • Posts: 10
Re: TIDHTTP can't read file on server
« Reply #3 on: July 01, 2014, 10:56:50 am »
Thank you Taazz and ChrisF for the replies. I am a complete noob when it comes to programming with Indy, so I didn't know about the HandleRedirects and User-Agent. I set those to what you suggested and everything seems to work perfectly fine! Thanks a lot  :D

 

TinyPortal © 2005-2018