Alaska Software Inc. - LoadFromUrl HTML header
Username: Password:
AuthorTopic: LoadFromUrl HTML header
Evgeny Bogolyubov LoadFromUrl HTML header
on Wed, 09 Apr 2003 20:02:06 +0200
Hi All,

Working with the LoadFromUrl() function I fund one really inconvenient 
feature of this function. The function automatically adds html header to 
the request I send to the host, something like:

POST /myPath/1 HTTP/1.1
Host: 127.0.0.1:80
Content-Type: application/x-www-form-urlencoded
Content-Length: 221

That all looks OK to me except the Content-Type attribute. In my case it 
should be "multipart/mixed", but I cannot override that attribute. At least 
I don see how 8-(.
So, my question to All is: Can I change the "Content-Type" attribute or 
suppress that header at all. I'm sure that many people already experienced 
that problem. Please help!

Thank you in advance for your help.

Regards,
Evgeny.
phil@compucar.net Re: LoadFromUrl HTML header
on Thu, 10 Apr 2003 08:58:38 +0000
>Working with the LoadFromUrl() function I fund one really inconvenient 
>feature of this function. The function automatically adds html header to 
>the request I send to the host, something like:
>
>POST /myPath/1 HTTP/1.1
>Host: 127.0.0.1:80
>Content-Type: application/x-www-form-urlencoded
>Content-Length: 221
>
>That all looks OK to me except the Content-Type attribute. In my case it 
>should be "multipart/mixed", but I cannot override that attribute. At least 
>I don see how 8-(.
>So, my question to All is: Can I change the "Content-Type" attribute or 
>suppress that header at all. I'm sure that many people already experienced 
>that problem. Please help!

Unless Alaska show us some undocumented parameters, then no you can't.
However, you have discovered all the information you need to write
your own version:

#include "asinetc.ch"
#define CRLF Chr(13)+Chr(10)

Function MyLoadFromUrl( cUrl, nPort, cContentType )
   local nError := 0
   local cHost  := HostFromUrl(cUrl)
   local oSocket := SocketOpen(SOCK_STREAM,cHost,nPort,@nError)
   local cBuff

   default cContentType to "application/x-www-form-urlencoded"
   
   if nError == 0
      cBuff := "POST "+UriFromUrl(cUrl)+" HTTP/1.1"+CRLF+;
               "Host: "+cHost+":"+LTrim(Str(nPort))+CRLF+;
               "Content-Type: "+cContentType+CRLF+;
               "Content-Length: "+LTrim(Str(Len(UriFromUrl)))+CRLF+;
               CRLF
      if SocketSend(oSocket,cBuff) == Len(cBuff)
         cBuff := ""
         SocketRecv(oSocket, @cBuff)
      endif
   endif
   return cBuff  NIL or "" on error

Function HostFromUrl(cUrl)
   local cRet
   local nStart := 1
   local nEnd
   
   if left(lower(cUrl),7) == 'http://'
      nStart := 8
   endif
   nEnd := at( cUrl, '/', nStart )
   nEnd := iif( nEnd == 0, (len(cUrl)-nStart)+1, nEnd )
   Return SubStr( cUrl, nStart, nEnd-nStart )

Function UriFromUrl(cUrl)
   local nStart := iif( left(lower(cUrl),7) == 'http://', 8, 1 )
   Return SubStr( cUrl, nStart )

Regards,
      

Phil Ide

Xbase++ FAQ
current release: 8,  Monday 4th February 2002, 14:54
***
* Xbase++ FAQ:
*  online  : http://www.idep.org.uk/xbase/xbfaq/xbfaq.htm
*          : www.software-braun.de/xbfaq/xbfaq.htm 
*  download: http://www.idep.org.uk/xbase/xbfaq.zip
*          : www.software-braun.de/xbfaq/xbfaq.zip 
***
Evgeny Bogolyubov Re: LoadFromUrl HTML header
on Thu, 10 Apr 2003 19:59:55 +0200
Hi Phil,

Thank you for your help. Unfortunately I forgot to mention in my previous 
posing that the server I'm connecting is Secure HTTP. I'm not sure if I 
can use SocketOpen() for that (at least I don't know how to specify that 
 in my call). I believe the only function in ASINET working with 
secure connection if LoadFromUrl(). Please correct me if I'm wrong. 

Regards,
Evgeny. 


phil@compucar.net (Phil Ide) wrote in
news:3e952d16.2253139@news.alaska-software.com: 

>>Working with the LoadFromUrl() function I fund one really inconvenient
>>feature of this function. The function automatically adds html header
>>to the request I send to the host, something like:
>>
>>POST /myPath/1 HTTP/1.1
>>Host: 127.0.0.1:80
>>Content-Type: application/x-www-form-urlencoded
>>Content-Length: 221
>>
>>That all looks OK to me except the Content-Type attribute. In my case
>>it should be "multipart/mixed", but I cannot override that attribute.
>>At least I don see how 8-(.
>>So, my question to All is: Can I change the "Content-Type" attribute
>>or suppress that header at all. I'm sure that many people already
>>experienced that problem. Please help!
> 
> Unless Alaska show us some undocumented parameters, then no you can't.
> However, you have discovered all the information you need to write
> your own version:
> 
> #include "asinetc.ch"
> #define CRLF Chr(13)+Chr(10)
> 
> Function MyLoadFromUrl( cUrl, nPort, cContentType )
>    local nError := 0
>    local cHost  := HostFromUrl(cUrl)
>    local oSocket := SocketOpen(SOCK_STREAM,cHost,nPort,@nError)
>    local cBuff
> 
>    default cContentType to "application/x-www-form-urlencoded"
>    
>    if nError == 0
>       cBuff := "POST "+UriFromUrl(cUrl)+" HTTP/1.1"+CRLF+;
>                "Host: "+cHost+":"+LTrim(Str(nPort))+CRLF+;
>                "Content-Type: "+cContentType+CRLF+;
>                "Content-Length: "+LTrim(Str(Len(UriFromUrl)))+CRLF+;
>                CRLF
>       if SocketSend(oSocket,cBuff) == Len(cBuff)
>          cBuff := ""
>          SocketRecv(oSocket, @cBuff)
>       endif
>    endif
>    return cBuff  NIL or "" on error
> 
> Function HostFromUrl(cUrl)
>    local cRet
>    local nStart := 1
>    local nEnd
>    
>    if left(lower(cUrl),7) == 'http://'
>       nStart := 8
>    endif
>    nEnd := at( cUrl, '/', nStart )
>    nEnd := iif( nEnd == 0, (len(cUrl)-nStart)+1, nEnd )
>    Return SubStr( cUrl, nStart, nEnd-nStart )
> 
> Function UriFromUrl(cUrl)
>    local nStart := iif( left(lower(cUrl),7) == 'http://', 8, 1 )
>    Return SubStr( cUrl, nStart )
> 
> Regards,
>
phil@compucar.net Re: LoadFromUrl HTML header
on Fri, 11 Apr 2003 09:56:23 +0000
>Thank you for your help. Unfortunately I forgot to mention in my previous 
>posing that the server I'm connecting is Secure HTTP. I'm not sure if I 
>can use SocketOpen() for that (at least I don't know how to specify that 
> in my call). I believe the only function in ASINET working with 
>secure connection if LoadFromUrl(). Please correct me if I'm wrong. 

I know the docs say it works with secure connections, but unless I'm
grossly mistaken it can't. The reason for this is the way that HTTPS
works. The server sends the client a certificate, which the client is
then obliged to validate (by checking with the certificating
authority) or ignore. If it chooses not to ignore, then the validation
is only the start of the process. (Ignoring the certificate is the
same as accepting the certificate as valid without verification, and
accepting the certificate as trusted.)  Having asserted that the
certificate is valid, the client must then see whether the certificate
is on it's list of trusted certificates. It probably isn't, so the
client must then check the certificate of the issuing authority (fetch
CA certificate, validate) and repeat the process.

This continues until a valid certificate from a trusted source is
encountered, or the process fails (invalid certificate found or
reaching the top-level parent authority without find a trust).

Once a valid certificate is discovered and accepted, the client issues
a certificate of it's own.  At this stage, negotiation is complete and
the transactions can begin. All transactions are encrypted using the
certificates.

Unless LoadFromUrl() follows this sequence (which I doubt) then
interaction with an HTTPS server is not possible.

Regards,

Phil Ide

Xbase++ FAQ
current release: 8,  Monday 4th February 2002, 14:54
***
* Xbase++ FAQ:
*  online  : http://www.idep.org.uk/xbase/xbfaq/xbfaq.htm
*          : www.software-braun.de/xbfaq/xbfaq.htm 
*  download: http://www.idep.org.uk/xbase/xbfaq.zip
*          : www.software-braun.de/xbfaq/xbfaq.zip 
***