Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [VB.NET] WebHeaderCollection non accetta caratteri es ;
Forum - C# / VB.NET - [VB.NET] WebHeaderCollection non accetta caratteri es ;

Avatar
amreo (Normal User)
Pro


Messaggi: 93
Iscritto: 18/03/2013

Segnala al moderatore
Postato alle 12:46
Domenica, 27/04/2014
Ho un GROSSO problema.
Ho creato un codice in vb.net che data una stringa contenente un protocollo HTTP
es:
Codice sorgente - presumibilmente C# / VB.NET

  1. GET /wiki.com/Pagina_principale HTTP/1.1
  2. Connection: Keep-Alive
  3. User-Agent: Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)
  4. Accept: text/html, image/jpeg, image/png, text/*, image/*, */*
  5. Accept-Encoding: x-gzip, x-deflate, gzip, deflate, identity
  6. Accept-Charset: iso-8859-1, utf-8;q=0.5, *;q=0.5
  7. Accept-Language: en
  8. 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()
Codice sorgente - presumibilmente VB.NET

  1. Dim _hes As New WebHeaderCollection()
  2.         'aggiunge tutte le linee alla collezione
  3.         For Each he As String In header
  4.             'verifica che la linea sia corretta
  5.             Try
  6.                 'aggiunge l'header
  7.                 _hes.Add(he.Remove(he.IndexOf(":")), he.Substring(he.IndexOf(":") + 1)
  8.             Catch ex As Exception
  9.                  '[...]
  10.             End Try
  11.         Next



però mi da errore in quasi tutte le linee perchè ci sono caratteri es ;

PM Quote
Avatar
amreo (Normal User)
Pro


Messaggi: 93
Iscritto: 18/03/2013

Segnala al moderatore
Postato alle 16:37
Mercoledì, 30/04/2014
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.

Codice sorgente - presumibilmente VB.NET

  1. Dim _hes As New WebHeaderCollection()
  2.         'aggiunge tutte le linee alla collezione
  3.         For Each he As String In header
  4.             he = he.Trim
  5.             If he = "" Then Continue For
  6.             'verifica che la linea sia corretta
  7.             Try
  8.                 'aggiunge l'header
  9.                 _hes(he.Remove(he.IndexOf(":"))) = he.Substring(he.IndexOf(":") + 1)
  10.                 '_wr.Headers(he.Remove(he.IndexOf(":"))) = he.Substring(he.IndexOf(":") + 1)
  11.             Catch ex As Exception
  12.                 'Setta bad request
  13.                 _sc = "400 Bad Request"
  14.             End Try
  15.         Next
  16.  
  17.         'Se tento di settare le proprietà mi da errore!


PM Quote