Article View: pl.comp.lang.vbasic
Article #92454Re: HttpWebRequest a odpowiedz Chunked;
From: Andrzej J. Turowicz
Date: Sat, 29 Oct 2005 08:01
Date: Sat, 29 Oct 2005 08:01
127 lines
3736 bytes
3736 bytes
Ja to robię tak
ponizsza funkcja to moja modyfikacja pewnego kodu z godotnet
dołącz bibliotekę w vBasic a w niej umieść funkcję
CzytajStroneWWWZInternetuB
Jak Ci będzie "pasowała" to przetłumacz ją sobie na C#
Private Function CzytajStroneWWWZInternetuB(ByVal Adres_ As String) As
String
Dim Wynik_ As String
Wynik_ = ""
Try
Dim req As WebRequest
Dim result As WebResponse
Dim ReceiveStream As Stream
Dim encode As System.Text.Encoding
Dim sr As StreamReader
Wynik_ = ""
req = WebRequest.Create(Adres_)
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()
'encode = System.Text.Encoding.GetEncoding("utf-8")
encode = System.Text.Encoding.Default
'encode = System.Text.Encoding.GetEncoding("iso-8859-2")
sr = New StreamReader(ReceiveStream, encode)
Console.WriteLine()
Console.WriteLine("Response stream received")
Dim read(256) As Char
Dim count As Integer = sr.Read(read, 0, 256)
Console.WriteLine("HTML...")
Console.WriteLine()
Do While count > 0
Dim str As String = New String(read, 0, count)
Wynik_ += str
Console.Write(str)
count = sr.Read(read, 0, 256)
Loop
Console.WriteLine("")
Catch Exc As Exception
Console.WriteLine()
Console.WriteLine("The request URI could not be found or was malformed")
End Try
Dim Ile_ As Integer
Ile_ = Len(Wynik_)
Return Wynik_
End Function
--
Pozdrawiam
Andrzej
www.turowicz.pl wap.buchalter.com.pl
-
Użytkownik "adas;" <pindolpindol@WYTNIJ.gazeta.pl> napisał w wiadomości
news:dju12t$djc$1@inews.gazeta.pl...
> Witam!
>
> Moj problem dotyczy w zasadzie .NET C#, ale ogolnie jest to
> srodowisko .NET visual studio i podejrzewam, ze w vbasic
> jest ten sam problem;
>
> otoz mam stronke WWW, ktora chce pobrac za pomoca klas:
> HttpWebRequest, HttpWebResponse:
>
> HttpWebRequest zapytanie =
> new (HttpWebRequest)WebRequest.Create("http://host/sciezka/");
> HttpWebResponse odpowiedz = (HttpWebResponse)zapytanie.GetResponse();
> Stream strumien = odpowiedz.GetResponseStream();
> strumien.ReadToEnd() // error !!!
>
> problem pojawia sie, jezeli serwer WWW odpowiada mi naglowkiem
> Transfer-encoding: chunked; niestety serwer musi tak odpowiadac,
> bo moje zapytanie musi byc HTTP/1.1 (ze wzgledu na vhosty);
> StreamReader nie chce tego ruszyc; a klasa HttpWebResponse AFAIK
> nie ma zadnej innej metody, ktora zwracalaby tresc odpowiedzi :(
>
> czy wiecie jak sie dobrac do takiej pofragmentowanej odpowiedzi??
>
> PS: jezeli to zla grupa, to skierujscie na odpowiednia;
>
> pzdrv;
> adas;
>
> --
> Wysłano z serwisu Usenet w portalu Gazeta.pl ->
> http://www.gazeta.pl/usenet/
Technical Details
Message-ID:
<djva9k$l6c$1@nemesis.news.tpi.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mailReferences:
<dju12t$djc$1@inews.gazeta.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail From: "Andrzej J. Turowicz" <at@buchalter.com.pl.BEZ_SMIECI> Newsgroups: pl.comp.lang.vbasic Subject: Re: HttpWebRequest a odpowiedz Chunked; Date: Sat, 29 Oct 2005 10:01:05 +0200 Organization: tp.internet - http://www.tpi.pl/ Lines: 129 Message-ID: <djva9k$l6c$1@nemesis.news.tpi.pl> References: <dju12t$djc$1@inews.gazeta.pl> NNTP-Posting-Host: 80.51.98.81 X-Trace: nemesis.news.tpi.pl 1130572917 21708 80.51.98.81 (29 Oct 2005 08:01:57 GMT) X-Complaints-To: usenet@tpi.pl NNTP-Posting-Date: Sat, 29 Oct 2005 08:01:57 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit