#1 2017-05-22 03:54:14

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

HttpGet failed in TestSQL3

Strangely, all HttpGet failed in SynSelfTest unit when I ran TestSQL3 compiled with Berlin 10.2 Starter and Delphi 2007 Enterprise. The URL's corresponding json file needs to be delete to get the HttpGet line executed.

The error is "Project TestSQL3.exe raised exception class EWinHTTP with message 'winhttp.dll error 12029 (A connection with the server could not be established)'.

The URLs are all fine if open them with browser. Also tested URLs with PostMan and AdvancedREST Client, two of them need to specify header "User-Agent", otherwise all fine.

HttpGet seems working with "http" version of the URLs instead of "https" version.

Any pointer?

Last edited by Bo (2017-05-22 03:54:26)

Offline

#2 2017-05-22 20:40:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: HttpGet failed in TestSQL3

Firewall issue?
Are you behind a corporate proxy?

Offline

#3 2017-05-22 23:38:03

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Re: HttpGet failed in TestSQL3

No proxy, but could be firewall as it runs OK outside of firewall, but what settings could be?

I then wrote a simple test application with RAD 10.2:

One form with two buttons, one button call mORMot's HttpGet, another one use TNetHttpRequest which comes with RAD 10.2,

code behind mORMot's button:   

procedure TDetailViewForm.Button1Click(Sender: TObject);
begin
  memo1.Text :=  HttpGet(Edit1.Text);
end;

code behind TNetHTTPRequest button: 

procedure TDetailViewForm.Button2Click(Sender: TObject);
begin
  NetHttpRequest1.URL := Edit1.Text;
  NetHttpRequest1.Execute();
end;

code for response from TNetHTTPRequest:

procedure TDetailViewForm.NetHTTPRequest1RequestCompleted(const Sender: TObject;
  const AResponse: IHTTPResponse);
begin
  Memo1.Text := AResponse.ContentAsString();
end;

Ran on a machine with URL "https://shop.global-health.com", mORMot button did not get response, but TNetHTTPRequest did. If URL changed to "http://shop.global-health.com", both worked.

If we bought an application developed in mORMot and it has this problem, what can our IT guy do to find out what issue could be in the company's firewall/network settings?

Offline

#4 2017-05-23 07:02:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: HttpGet failed in TestSQL3

I can't reproduce the issue here.
The following is working:

var s: Sockstring;
begin
  s := HttpGet('https://shop.global-health.com');
  writeln(s);
end.

Which version of the framework are you using?
Please use the latest unstable revision.
Current version is 1.18.3672.

Offline

#5 2017-05-24 06:46:21

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Re: HttpGet failed in TestSQL3

Tried today's Github's copy, still failed.

Checked Delphi's TNetHTTPClient and TNetHTTPRequest, they are using winhttp.dll as well.

I also try to call functions of WinHTTP directly:

procedure TDetailViewForm.Button1Click(Sender: TObject);
var
  hSession : HINTERNET;
  hConnect : HINTERNET;
  hRequest : HINTERNET;
  hResult : Boolean;
  dwSize : DWord;
begin
//  memo1.Text :=  HttpGet(Edit1.Text);
  hSession := WinHttpOpen('Mozilla/5.0 (Windows; mORMot 1.18 TWinHTTP)',WINHTTP_ACCESS_TYPE_NO_PROXY,'','',0);
  if (hSession=nil) then raise Exception.Create('Failed to create session');
  hConnect := WinHttpConnect(hSession,'shop.global-health.com',443,0);
  if (hConnect=nil) then raise Exception.Create('Failed to connect');
  hRequest := WinHttpOpenRequest(hConnect,'GET','/',nil,nil,nil,8388864);
  if (hRequest=nil) then raise Exception.Create('Failed to open request');
  if not WinHttpSendRequest(hRequest,nil,0,0,0,0,0) then
  begin
    raise Exception.Create(IntToStr(GetLastError()))
  end;
  hResult := WinHttpReceiveResponse(hRequest,nil);
  if not hResult then raise Exception.Create('Failed to receive data, error:' + inttostr(GetLastError()));

end;

the value of parameters to the function calls are copied from debuging HttpGet, these code has not failure with "WINHTTP_ACCESS_TYPE_NO_PROXY", but will get error 12029 when calling WinHttpSendRequest if change it to WINHTTP_ACCESS_TYPE_DEFAULT_PROXY.

I then change code in SynCrtSock (line 8266 of 24/5/2017) from

if fProxyName='' then
    OpenType := WINHTTP_ACCESS_TYPE_DEFAULT_PROXY else
    OpenType := WINHTTP_ACCESS_TYPE_NAMED_PROXY;

to

if fProxyName='' then
    OpenType := WINHTTP_ACCESS_TYPE_NO_PROXY else
    OpenType := WINHTTP_ACCESS_TYPE_NAMED_PROXY;

and it works for my machine.

But why? Is it a bug or I should change my system/network settings?

Last edited by Bo (2017-05-24 07:43:10)

Offline

#6 2017-05-24 11:48:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: HttpGet failed in TestSQL3

Offline

Board footer

Powered by FluxBB