Connecting Tech Pros Worldwide Help | Site Map

Open a https url on a special port ? (asp/ajax inside)

Arnaud
Guest
 
Posts: n/a
#1: Mar 17 '06
Hi,

I'm trying to translate an asp application in a php way, i'm using Php
4.3.x.
I'm going to try an asp newsgroup too, but as it mainly deals with Php, I
would like to submit you my probem :

I have to retrieve some XML datas from a server whose URL is built like that
:
https://myserver:4012/code/myapp?param1=3;

I tried fopen, fsockopen with no result.

So it's https, there is a port (4012 for example). Perhaps I forgot some
particular https parameters with my fopen and fsockopen tries ?

The original asp code is :
---
Set myxml = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
' Opens the connection to the remote server :
xml.Open "GET", url, False
---

Php methods didn't work so I tried the ajax way :
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert('Problem creating the XMLHttpRequest object');
return false;
}
return req;

.... But i'm not sure the ActiveXObject is identical to the original :
Set myxml = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")

So if you have any ideas to do it with Php or any other technical ways, you
are welcome.

Thanks,
Arnaud



Tim Van Wassenhove
Guest
 
Posts: n/a
#2: Mar 17 '06

re: Open a https url on a special port ? (asp/ajax inside)


On 2006-03-17, Arnaud <no> wrote:[color=blue]
> I'm trying to translate an asp application in a php way, i'm using Php
> 4.3.x.[/color]

[snip asp code]
[color=blue]
> So if you have any ideas to do it with Php or any other technical ways, you
> are welcome.[/color]

And where is the code that you've already tried but didn't work?

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
NC
Guest
 
Posts: n/a
#3: Mar 17 '06

re: Open a https url on a special port ? (asp/ajax inside)


Arnaud wrote:[color=blue]
>
> I have to retrieve some XML datas from a server whose URL is built like that
> :
> https://myserver:4012/code/myapp?param1=3;
>
> I tried fopen, fsockopen with no result.[/color]

What exactly did you try and what kind of "no result" have you achieved
(error messages, etc.)?

Also, have you tried cURL?

Cheers,
NC

Arnaud
Guest
 
Posts: n/a
#4: Mar 17 '06

re: Open a https url on a special port ? (asp/ajax inside)



"Tim Van Wassenhove" <timvw@users.sourceforge.net> a écrit dans le message
de news: dvemlp$8fv$1@ikaria.belnet.be...[color=blue]
> On 2006-03-17, Arnaud <no> wrote:
> And where is the code that you've already tried but didn't work?[/color]

Classical fsockopen or fopen :
if ($handle = fopen($url_complete, "r"))
echo 'ok';
else
echo 'ko';

I also tried several syntax with the fsockopen (ssl://...) but i always
obtain :
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or
service not known (is your IPV6 configuration correct? If this error happens
all the time, try reconfiguring PHP using --disable-ipv6 option to
configure) in...

Arnaud


Arnaud
Guest
 
Posts: n/a
#5: Mar 17 '06

re: Open a https url on a special port ? (asp/ajax inside)



"NC" <nc@iname.com> a écrit dans le message de news:
1142613530.709211.49000@z34g2000cwc.googlegroups.c om...[color=blue]
> What exactly did you try and what kind of "no result" have you achieved
> (error messages, etc.)?[/color]

if ($handle = fsockopen('https://myserver:4012/code/param?', 80, $errno,
$errstr))...
or
if ($handle = fsockopen('https://myserver:4012/code/param?', 4012, $errno,
$errstr))...
or
if ($handle = fsockopen('https://myserver/code/param?', 4012, $errno,
$errstr))...
[color=blue]
> Also, have you tried cURL?[/color]

Not yet, but i'm looking at it, i can see in my phpinfo :
CURL support enabled
CURL Information libcurl/7.12.2 OpenSSL/0.9.7d zlib/1.1.4

thanks,
arnaud


NC
Guest
 
Posts: n/a
#6: Mar 17 '06

re: Open a https url on a special port ? (asp/ajax inside)


Arnaud wrote:[color=blue]
> "NC" <nc@iname.com> a écrit dans le message de news:
> 1142613530.709211.49000@z34g2000cwc.googlegroups.c om...
>[color=green]
> > What exactly did you try and what kind of "no result" have you achieved
> > (error messages, etc.)?[/color]
>
> if ($handle = fsockopen('https://myserver:4012/code/param?', 80, $errno,
> $errstr))...
> or
> if ($handle = fsockopen('https://myserver:4012/code/param?', 4012, $errno,
> $errstr))...
> or
> if ($handle = fsockopen('https://myserver/code/param?', 4012, $errno,
> $errstr))...[/color]

But of course it didn't work... Have you even looked at fsockopen()
documentation? Check it out:

http://www.php.net/fsockopen

The correct usage of fsockopen() in your case would be something like
this:

$host = 'myserver';
$port = 4012;
$path = 'code/myapp?param1=3';
$fp = fsockopen($host, $port, $errno, $errstr);
if ($fp) {
fputs($fp, "GET $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n\r\n");
} else {
die ("Could not connect to $host on port $port: error $errno
($errstr)");
}
$data = '';
while (!feof ($fp)) {
$data .= fgets ($fp, 10240);
}
fclose ($fp);

Now $data should contain the entire HTTP response, including HTTP
headers...

Cheers,
NC

Arnaud
Guest
 
Posts: n/a
#7: Mar 20 '06

re: Open a https url on a special port ? (asp/ajax inside)


<"NC" <nc@iname.com> a écrit dans le message de news:
1142619000.711712.38050@j33g2000cwa.googlegroups.c om...
<But of course it didn't work... Have you even looked at fsockopen()
<documentation? Check it out:
<http://www.php.net/fsockopen
<The correct usage of fsockopen() in your case would be something like
<this:
<$host = 'myserver';
<$port = 4012;
<$path = 'code/myapp?param1=3';
<$fp = fsockopen($host, $port, $errno, $errstr);
<[...]
<Now $data should contain the entire HTTP response, including HTTP
<headers...

Hi,
Yes, I tried that way too, but it didn't work either, the problem was a bad
ip, it's resolved now.
Thanks for your time and help.

Arnaud


Closed Thread