Oppure

Loading
27/04/14 10:46
amreo
Ho un GROSSO problema.
Ho creato un codice in vb.net che data una stringa contenente un protocollo HTTP
es:
GET /wiki.com/Pagina_principale HTTP/1.1 
Connection: Keep-Alive
User-Agent: Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)
Accept: text/html, image/jpeg, image/png, text/*, image/*, */*
Accept-Encoding: x-gzip, x-deflate, gzip, deflate, identity
Accept-Charset: iso-8859-1, utf-8;q=0.5, *;q=0.5 
Accept-Language: en
Host: it.wikipedia.org

La legge è mi imposta le proprietà di un WebRequest.
per farlo ho creato un codice che divide la stringa in più parti(dividendo le sottostringhe da VbCrLf.
poi ho forato con for each: ogni linea viene aggiunto al WebHeaderCollection()
       Dim _hes As New WebHeaderCollection()
        'aggiunge tutte le linee alla collezione
        For Each he As String In header
            'verifica che la linea sia corretta
            Try
                'aggiunge l'header
                _hes.Add(he.Remove(he.IndexOf(":")), he.Substring(he.IndexOf(":") + 1)
            Catch ex As Exception
                 '[...]
            End Try
        Next


però mi da errore in quasi tutte le linee perchè ci sono caratteri es ;
aaa
30/04/14 14:37
amreo
RISOLTO!! (parzialmente)
sono riuscito a risolvere parzialmente il problema, però non riesco a settare le proprietà.
Le errore è che nella coppia (di tipo string) Nome:valore c'erano alcuni caratteri con VbCrLf. io ho trimmato la stringa e saltata la linea nel caso fosse vuota.

    Dim _hes As New WebHeaderCollection()
        'aggiunge tutte le linee alla collezione
        For Each he As String In header
            he = he.Trim
            If he = "" Then Continue For
            'verifica che la linea sia corretta
            Try
                'aggiunge l'header
                _hes(he.Remove(he.IndexOf(":"))) = he.Substring(he.IndexOf(":") + 1)
                '_wr.Headers(he.Remove(he.IndexOf(":"))) = he.Substring(he.IndexOf(":") + 1)
            Catch ex As Exception
                'Setta bad request
                _sc = "400 Bad Request"
            End Try
        Next

        'Se tento di settare le proprietà mi da errore!
aaa