Re: using connection and https

Fernand Vanrie <[email protected]> Wed, 25 May 2011 16:01:35 +0200
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
Christian ,

Thanks for your valuable help.

After i succeeded to use the OO connection stuff to use Google=20
Translations i was tempted to use the newest Google Tasks API too.

Using port 443  i get no respons at all ?
I left my API_Key out for security reasons.
But

In my working code for Translations i used
GET http://ajax.googleapis.com/....

so i am a bit confused about the syntax to make HHTP requests :-)

sub GoogleTranslate
cCR =3D Chr(13)
cLF =3D Chr(10)
oConnector =3D createUnoService("com.sun.star.connection.Connector")
oConnection =3D=20
oConnector.connect("socket,host=3Dwww.googleapis.com,port=3D80")=20
'je%20suis%20au%20l'int=E9rieur%20du%20magazin
sToTranslate =3D "voetbal"
sSourceLang =3D "nl"
sTargetLang =3D "en"
oConnection.write( StringToByteArray( "GET=20
http://ajax.googleapis.com/ajax/services/language/translate?v=3D1.0&q=3D"=
&=20
sToTranslate & "&langpair=3D" & sSourceLang & "|" & sTargetlang  + cCR +=20
cLF+ cCR +cLF ) )
oConnection.flush()
aByteArray  =3D Array()
nBytesRead =3D oConnection.read(aByteArray, 1000)
  oPipe    =3D createUNOService ("com.sun.star.io.Pipe") ' heeft zowel ee=
n=20
In als OUtput stream
oTextInp =3D createUNOService ("com.sun.star.io.TextInputStream") 'kan le=
zen
oTextOut =3D createUNOService ("com.sun.star.io.TextOutputStream")' kan=20
schrijven
oTextInp.setInputStream(opipe) 'maakt dat pipe kan lezen
otextOut.setOutputStream(opipe) 'maakt dat pipe kan schrijven
otextout.setencoding("ISO-8859-1")
otextOut.writestring(ByteArrayToString(aByteArray)) 'schrijft de string=20
naar Pipe
s =3D oTextinp.readstring(Array("}"), true)
msgbox(s)
end sub

> Hi Fernand, *,
>
> On Wed, May 25, 2011 at 9:24 AM, Fernand Vanrie<[email protected]>  wrote:
>> I trie to connect to Googleapis using OO and https ?
>>
>> Code:
>> oConnector =3D createUnoService("com.sun.star.connection.Connector")
>> oConnection =3D oConnector.connect("socket,host=3Dwww.googleapis.com,p=
ort=3D80")
> first: don't know whether it is  supported by OOo like this, but your
> example has several general problems, so here we go...
>
> If you want to use ssl, then you should try with the default ssl-port (=
443)
>
>> oConnection.write( StringToByteArray( "GET
>> https://www.googleapis.com/tasks/v1/lists/MDk5Nzc1MDY0NzQyMTk4NjEyMzM6=
MDow/tasks/MDk5Nzc1MDY0NzQyMTk4NjEyMzM6MDo4?pp=3D1&key=3D
> And http GET doesn't include the hostname, just the path. Specify the
> host in the Host parameter.
>
> <https://www.googleapis.com/tasks/v1/lists/MDk5Nzc1MDY0NzQyMTk4NjEyMzM6=
MDow/tasks/MDk5Nzc1MDY0NzQyMTk4NjEyMzM6MDo4?pp=3D1&key=3D>{YOUR_API_KEY}"
>
> and you're not supposed to write it twice either, but maybe I'm
> getting things wrong here.
> And obviously "YOUR_API_KEY" is to be replaced by your API key.
>
> it's
> GET /path/to?param=3Dvalue&param2=3Dvalue2 HTTP/1.1
> Host: www.myhost.com
> Connection: close
>
> (well, connection: close as it is the only request, you can also just
> use http 1.0 request that only have one request at a time anyway)
>
> ciao
> Christian

--=20
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help