There are classes that mimic the old WinInet API?

D

dev

Hi to all,

I am a sofware developer with few months experience in C#. I worked in C/C++
and, time ago, developed an application to receive a video-stream (MJPEG)
via http.

Simply I used the standard WinInet API such as InternetOpen(),
InternetConnect(), HttpOpenRequest(), InternetReadFile() and so on...

I just wanted to know what classes in C# accomplish those basic http
functions. If you can point me to the correct reference on MSDN .NET or some
tutorials/docs on the web.

Thanks a lot

Dev[eloper].
 
A

Anthony Yio

You can use PInvoke to call the Win23 API.

or try to look into System.Net for the goodies that they have.
 
D

dev

Thank Anthony for your reply,

But I want to avoid calling directly the native API, too much problems and
overhead work (but still a feasible road if I can't find what I want).

Also, I was searching on System.Net but got confused about FileRequest,
HttpRequest and so on.

Any more precise hints?

Bye

Dev

Anthony Yio said:
You can use PInvoke to call the Win23 API.

or try to look into System.Net for the goodies that they have.


dev said:
Hi to all,

I am a sofware developer with few months experience in C#. I worked in C/C++
and, time ago, developed an application to receive a video-stream (MJPEG)
via http.

Simply I used the standard WinInet API such as InternetOpen(),
InternetConnect(), HttpOpenRequest(), InternetReadFile() and so on...

I just wanted to know what classes in C# accomplish those basic http
functions. If you can point me to the correct reference on MSDN .NET or some
tutorials/docs on the web.

Thanks a lot

Dev[eloper].
 
S

Sam Gentile [MVP - C#/.NET]

What specifically are you having a problem with in System.Net so that we may
better answer your question? System.Net has everything you need. There is no
need to go to native code.

--
----------------------------------
Sam Gentile
MVP - C#/.NET
INETA Speaker http://www.ineta.org/DesktopDefault.aspx
Read my blog at http://samgentile.com/blog/
------------------------------------------------------
dev said:
Thank Anthony for your reply,

But I want to avoid calling directly the native API, too much problems and
overhead work (but still a feasible road if I can't find what I want).

Also, I was searching on System.Net but got confused about FileRequest,
HttpRequest and so on.

Any more precise hints?

Bye

Dev

Anthony Yio said:
You can use PInvoke to call the Win23 API.

or try to look into System.Net for the goodies that they have.


dev said:
Hi to all,

I am a sofware developer with few months experience in C#. I worked in C/C++
and, time ago, developed an application to receive a video-stream (MJPEG)
via http.

Simply I used the standard WinInet API such as InternetOpen(),
InternetConnect(), HttpOpenRequest(), InternetReadFile() and so on...

I just wanted to know what classes in C# accomplish those basic http
functions. If you can point me to the correct reference on MSDN .NET
or
some
tutorials/docs on the web.

Thanks a lot

Dev[eloper].
 
D

dev

Dear Sam,

What class is needed to read a binary file from an http server (my camera
furnish a MJPEG stream)?

I was surfing on the doc about HttpWebRequest, I doesn't recognize any
method similar to the WinInet. But is it (HttpWebRequest) the class I need?
Any Sample around?

Thanks.

PS: You have an Italian surname, are you originating from that place?



Sam Gentile said:
What specifically are you having a problem with in System.Net so that we may
better answer your question? System.Net has everything you need. There is no
need to go to native code.

--
----------------------------------
Sam Gentile
MVP - C#/.NET
INETA Speaker http://www.ineta.org/DesktopDefault.aspx
Read my blog at http://samgentile.com/blog/
------------------------------------------------------
dev said:
Thank Anthony for your reply,

But I want to avoid calling directly the native API, too much problems and
overhead work (but still a feasible road if I can't find what I want).

Also, I was searching on System.Net but got confused about FileRequest,
HttpRequest and so on.

Any more precise hints?

Bye

Dev

Anthony Yio said:
You can use PInvoke to call the Win23 API.

or try to look into System.Net for the goodies that they have.


Hi to all,

I am a sofware developer with few months experience in C#. I worked in
C/C++
and, time ago, developed an application to receive a video-stream (MJPEG)
via http.

Simply I used the standard WinInet API such as InternetOpen(),
InternetConnect(), HttpOpenRequest(), InternetReadFile() and so on...

I just wanted to know what classes in C# accomplish those basic http
functions. If you can point me to the correct reference on MSDN .NET or
some
tutorials/docs on the web.

Thanks a lot

Dev[eloper].
 
J

Joerg Jooss

dev said:
Dear Sam,

What class is needed to read a binary file from an http server (my
camera furnish a MJPEG stream)?

I was surfing on the doc about HttpWebRequest, I doesn't recognize any
method similar to the WinInet. But is it (HttpWebRequest) the class I
need? Any Sample around?

Well, it's hard to compare a procedural API with and OO API, but
(Http)WebRequest is what you want.

Here's a sample C# method for HTTP GETting a web resource and dumping it on
the console:

public void Get(Uri uri) {
WebRequest request = WebRequest.Create(uri);

using (Stream responseStream =
request.GetResponse().GetResponseStream()) {
MemoryStream memoryStream = new MemoryStream(0x10000);
byte[] buffer = new byte[0x1000];
int bytes;
while ((bytes = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
memoryStream.Write(buffer, 0, bytes);
}


// Assume ISO-8859-1 encoding of web resource -- normally we'd parse
this
// from the Content-Type header.
byte[] response = memoryStream.ToArray();
string text = Encoding.GetEncoding(28591).GetString(response);
Console.WriteLine(text);
}
}

If you replace the MemoryStream with a FileStream and remove the console
ouput, you have a basic download-to-file method.

Cheers,
 
D

dev

Thank you very much Joerg. This helps!

Dev

Joerg Jooss said:
dev said:
Dear Sam,

What class is needed to read a binary file from an http server (my
camera furnish a MJPEG stream)?

I was surfing on the doc about HttpWebRequest, I doesn't recognize any
method similar to the WinInet. But is it (HttpWebRequest) the class I
need? Any Sample around?

Well, it's hard to compare a procedural API with and OO API, but
(Http)WebRequest is what you want.

Here's a sample C# method for HTTP GETting a web resource and dumping it on
the console:

public void Get(Uri uri) {
WebRequest request = WebRequest.Create(uri);

using (Stream responseStream =
request.GetResponse().GetResponseStream()) {
MemoryStream memoryStream = new MemoryStream(0x10000);
byte[] buffer = new byte[0x1000];
int bytes;
while ((bytes = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
memoryStream.Write(buffer, 0, bytes);
}


// Assume ISO-8859-1 encoding of web resource -- normally we'd parse
this
// from the Content-Type header.
byte[] response = memoryStream.ToArray();
string text = Encoding.GetEncoding(28591).GetString(response);
Console.WriteLine(text);
}
}

If you replace the MemoryStream with a FileStream and remove the console
ouput, you have a basic download-to-file method.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top