Click here to Skip to main content
15,914,066 members
Home / Discussions / C#
   

C#

 
GeneralRe: problem with visual studio .net 2003 Pin
Gulfraz Khan8-Nov-05 0:09
Gulfraz Khan8-Nov-05 0:09 
Questionhttp://www.codeproject.com/csharp/minihttpd.asp Pin
sayangoin7-Nov-05 1:15
sayangoin7-Nov-05 1:15 
AnswerRe: http://www.codeproject.com/csharp/minihttpd.asp Pin
mav.northwind7-Nov-05 20:26
mav.northwind7-Nov-05 20:26 
Questiondownload image over http Pin
g00fyman7-Nov-05 0:54
g00fyman7-Nov-05 0:54 
AnswerRe: download image over http Pin
David Stone7-Nov-05 9:34
sitebuilderDavid Stone7-Nov-05 9:34 
GeneralRe: download image over http Pin
g00fyman7-Nov-05 10:26
g00fyman7-Nov-05 10:26 
GeneralRe: download image over http Pin
Jon Rista8-Nov-05 7:35
Jon Rista8-Nov-05 7:35 
GeneralRe: download image over http Pin
g00fyman8-Nov-05 13:07
g00fyman8-Nov-05 13:07 
sorry here is the entire code.

internal void Run()
{
  // the HTTP messages from client
  string message = "";

  // the complete request URI
  string uriString;

  // the encoding to use on the response data
  Encoding encoding;

  try
  {
    byte[] read = new byte[1024];

    // get the bytes of the request
    int bytes = this.m_socket.Receive(read);
    message = Encoding.ASCII.GetString(read);
    if (bytes < 1)
    {
      return;
    }
    // get the address of the host in the request
    HttpHeaderParser parser = new HttpHeaderParser(message);
    uriString = parser.RequestUri;
    Debug.WriteLine("Received request to page: " + uriString);

    // get the request
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);

    // send the request and get a response
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Debug.WriteLine("Received response ... OK");

    try
    {
      encoding = Encoding.GetEncoding(response.ContentEncoding);
    }
    catch
    {
      encoding = Encoding.GetEncoding(1252);
    }
    WebHeaderCollection headers = response.Headers;
    string contentType = headers[HttpResponseHeader.ContentType];
    Debug.WriteLine(" ### Content Type: " + contentType);

    // get a reader to read the page in
    StreamReader reader = new StreamReader(response.GetResponseStream());

    if (contentType.StartsWith("image/"))
    {
      byte[] imageBuffer = new byte[reader.BaseStream.Length];
      reader.BaseStream.Read(imageBuffer, 0, (int)reader.BaseStream.Length);

      Debug.WriteLine("Sending " + contentType + " back to client");
      this.m_socket.Send(imageBuffer); //, imageBuffer.length, 0);
    }
    else
    {
      Debug.WriteLine("reading page content");
      string content = reader.ReadToEnd();

      Debug.WriteLine("Content read, length is: " + content.Length);

      byte[] buffer = new byte[content.Length + 1];

      Debug.WriteLine("Sending " + contentType + " back to client");

      int length = encoding.GetBytes(content, 0, content.Length, buffer, 0);
      this.m_socket.Send(buffer, length, 0);
    }
    // clean up the reader and web response
    response.Close();
    reader.Close();

    this.m_socket.Shutdown(SocketShutdown.Both);
    this.m_socket.Close();

  }
  catch (Exception e)
  {
    Debug.WriteLine(" ***** Exception: " + e.Message);
  }
}


thank you
g00fy
QuestionCombining Cells Probs Pin
tadhg887-Nov-05 0:44
tadhg887-Nov-05 0:44 
GeneralRe: Combining Cells Probs Pin
Vikram A Punathambekar7-Nov-05 1:58
Vikram A Punathambekar7-Nov-05 1:58 
AnswerRe: Combining Cells Probs Pin
J4amieC7-Nov-05 2:35
J4amieC7-Nov-05 2:35 
QuestionSet File Access (Read/ReadWrite/Write) Pin
M-20006-Nov-05 23:59
M-20006-Nov-05 23:59 
AnswerRe: Set File Access (Read/ReadWrite/Write) Pin
Tom Larsen7-Nov-05 5:52
Tom Larsen7-Nov-05 5:52 
QuestionRe: Set File Access (Read/ReadWrite/Write) Pin
M-20007-Nov-05 21:02
M-20007-Nov-05 21:02 
QuestionHowto download a file from http-site Pin
Ariadne6-Nov-05 23:42
Ariadne6-Nov-05 23:42 
AnswerRe: Howto download a file from http-site Pin
Colin Angus Mackay6-Nov-05 23:51
Colin Angus Mackay6-Nov-05 23:51 
GeneralRe: Howto download a file from http-site Pin
Ariadne6-Nov-05 23:59
Ariadne6-Nov-05 23:59 
GeneralRe: Howto download a file from http-site Pin
Colin Angus Mackay7-Nov-05 1:14
Colin Angus Mackay7-Nov-05 1:14 
AnswerRe: Howto download a file from http-site Pin
Ariadne7-Nov-05 3:00
Ariadne7-Nov-05 3:00 
GeneralRe: Howto download a file from http-site Pin
jkersch7-Nov-05 3:47
jkersch7-Nov-05 3:47 
GeneralRe: Howto download a file from http-site Pin
Ariadne7-Nov-05 4:04
Ariadne7-Nov-05 4:04 
Questionremove the begining of a string Pin
Anthony Mushrow6-Nov-05 22:58
professionalAnthony Mushrow6-Nov-05 22:58 
AnswerRe: remove the begining of a string Pin
User 66586-Nov-05 23:05
User 66586-Nov-05 23:05 
QuestionBreak tags Pin
Brendan Vogt6-Nov-05 22:19
Brendan Vogt6-Nov-05 22:19 
AnswerRe: Break tags Pin
Colin Angus Mackay6-Nov-05 23:42
Colin Angus Mackay6-Nov-05 23:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.