Click here to Skip to main content
15,904,817 members
Home / Discussions / C#
   

C#

 
GeneralRe: What is this friggin .config file? Pin
led mike19-Nov-08 5:31
led mike19-Nov-08 5:31 
GeneralRe: What is this friggin .config file? Pin
Dewald19-Nov-08 6:00
Dewald19-Nov-08 6:00 
Questionefficient Pin
dole.doug17-Nov-08 4:05
dole.doug17-Nov-08 4:05 
AnswerRe: efficient Pin
Pr@teek B@h!17-Nov-08 4:11
Pr@teek B@h!17-Nov-08 4:11 
GeneralRe: efficient Pin
dole.doug17-Nov-08 5:07
dole.doug17-Nov-08 5:07 
AnswerRe: efficient Pin
Ennis Ray Lynch, Jr.17-Nov-08 5:04
Ennis Ray Lynch, Jr.17-Nov-08 5:04 
AnswerRe: efficient Pin
Alan Balkany18-Nov-08 3:39
Alan Balkany18-Nov-08 3:39 
QuestionHTTP POST problem Pin
gr9fci17-Nov-08 3:40
gr9fci17-Nov-08 3:40 
Hi all. I'm having a slight problem. I'm trying to write a method for performing HTTP GET and POST requests. It all works fine, but the problem I'm having is that the request gets sent without the parameters I've passed. The server then responds, and only then are the parameters sent. In one particular case, I'm trying to replicate the request in my application that is sent by internet explorer. In internet explorer, the headers and parameters are sent as a single request.

I used a packet sniffer to see what was going on. 
In my application, this is the first frame sent:
http://img511.imageshack.us/img511/921/appframe1ag8.jpg


This is the second frame sent:
http://img511.imageshack.us/img511/8359/appframe2zy4.jpg


In comparison, this is the single frame sent in internet explorer (note that the payload at the bottom is combined as part of the request, which is what I want to achieve):
http://img514.imageshack.us/img514/8342/ieframe1fr7.jpg


My code is as follows:



        /// <summary> 
        /// Performs an HTTP request 
        /// </summary> 
        /// <param name="uri">Uniform resource identifier</param> 
        /// <param name="method">HTTP request method (GET/POST)</param> 
        /// <param name="parameters">HTTP POST request parameters (example: "name1=value1&name2=value2")</param> 
        /// <param name="referer">Referer HTTP header URI</param> 
        /// <returns>Returns the server's response</returns> 
        public string HTTP_Request(string uri, string method, string parameters, string referer) 
        { 
            // Create a WebRequest object 
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); 
            // Set request properties 
            request.Method = method; 
            request.ContentType = @"application/x-www-form-urlencoded"
            request.CookieContainer = cookies; 
            request.KeepAlive = true
            request.Referer = referer; 
            request.UserAgent = @"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Win64; x64; .NET CLR 2.0.50727; SLCC1; Media Center PC 5.0;" + 
                ".NET CLR 3.5.30729; .NET CLR 3.0.30618"
            request.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, " + 
                "application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, */*"
            // If the HTTP request method is POST, send parameters to the server 
            if (method == "POST"
            { 
                byte[] buffer = Encoding.UTF8.GetBytes(parameters); 
                Stream dataStream = null
                try 
                { 
                    // Set the content length of the request data being sent 
                    request.ContentLength = buffer.Length; 
                    // Retrieve Stream object for writing data 
                    dataStream = request.GetRequestStream(); 
                    // Send data 
                    dataStream.Write(buffer, 0, buffer.Length); 
                } 
                catch (Exception) 
                { 
                    MessageBox.Show("HTTP_Request Error:\n\nRequest error"); 
                } 
                finally 
                { 
                    if (dataStream != null
                        dataStream.Close(); 
                } 
            } 
            // Get the HTTP request response 
            HttpWebResponse response = null
            StreamReader reader = null
            try 
            { 
                // Retrieve HttpWebResponse object containing the server's response 
                response = (HttpWebResponse)request.GetResponse(); 
                // Retrieve StreamReader object for reading data 
                reader = new StreamReader(response.GetResponseStream()); 
                // Return the trimmed server response 
                return reader.ReadToEnd().Trim(); 
            } 
            catch (Exception) 
            { 
                MessageBox.Show("HTTP_Request Error:\n\nResponse error"); 
            } 
            finally 
            { 
                if (response != null
                    response.Close(); 
                if (reader != null
                    reader.Close(); 
            } 
            return null
        } 


AnswerRe: HTTP POST problem Pin
leppie17-Nov-08 20:29
leppie17-Nov-08 20:29 
AnswerRe: HTTP POST problem Pin
leppie17-Nov-08 20:31
leppie17-Nov-08 20:31 
QuestionCreating a new WinForms .Net component (question from new comer) Pin
Ahmed Charfeddine17-Nov-08 2:55
Ahmed Charfeddine17-Nov-08 2:55 
Question.NET Runtime 2.0 Error Reporting Pin
jam198217-Nov-08 2:33
jam198217-Nov-08 2:33 
AnswerRe: .NET Runtime 2.0 Error Reporting Pin
sph3rex17-Nov-08 2:48
sph3rex17-Nov-08 2:48 
GeneralRe: .NET Runtime 2.0 Error Reporting Pin
jam198217-Nov-08 3:38
jam198217-Nov-08 3:38 
QuestionAbout binding files to an C# window application Pin
dilshan_02017-Nov-08 2:21
dilshan_02017-Nov-08 2:21 
AnswerRe: About binding files to an C# window application Pin
SeMartens17-Nov-08 2:32
SeMartens17-Nov-08 2:32 
GeneralRe: About binding files to an C# window application Pin
dilshan_02017-Nov-08 2:56
dilshan_02017-Nov-08 2:56 
GeneralRe: About binding files to an C# window application Pin
SeMartens17-Nov-08 4:31
SeMartens17-Nov-08 4:31 
Questiondatarow empty Pin
Melanie Booysen17-Nov-08 1:27
Melanie Booysen17-Nov-08 1:27 
AnswerRe: datarow empty Pin
SeMartens17-Nov-08 2:13
SeMartens17-Nov-08 2:13 
AnswerRe: datarow empty Pin
Andrew Rissing17-Nov-08 4:20
Andrew Rissing17-Nov-08 4:20 
QuestionConcat objects Pin
Scalee17-Nov-08 1:16
Scalee17-Nov-08 1:16 
AnswerRe: Concat objects Pin
Simon P Stevens17-Nov-08 1:47
Simon P Stevens17-Nov-08 1:47 
GeneralRe: Concat objects Pin
Scalee17-Nov-08 2:29
Scalee17-Nov-08 2:29 
QuestionDisplay image in Image control or Bitmap Pin
B8717-Nov-08 0:46
B8717-Nov-08 0:46 

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.