How do I retrieve the HTTP Status code (ie 202, 404, etc) below? I am
currently receiving the response text but unable to access the response
status code.
string strNewValue;
string strResponse;
// Create the request obj
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(txtURL.Text);
// Set values for the request back
req.Method = "POST";
//req.ContentType = "application/x-www-form-urlencoded";
strNewValue = Server.HtmlDecode(txtRequest.Value.ToString());
//req.ContentLength = strNewValue.Length;
req.
// Write the request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
// Do the request to get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream() );
strResponse = stIn.ReadToEnd();
stIn.Close();
txtResponse.Value = strResponse; 4 30218
Hi Chris,
HttpWebResponse rep = req.GetResponse();
HttpStatusCode c = rep.StatusCode;
when getting the response you may have to deal with exceptions if the
request is not successful so wrap it in a try-catch block.
Alex
"Chris Fink" <ch********@gmail.com> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl... How do I retrieve the HTTP Status code (ie 202, 404, etc) below? I am currently receiving the response text but unable to access the response status code.
string strNewValue;
string strResponse;
// Create the request obj
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(txtURL.Text);
// Set values for the request back
req.Method = "POST";
//req.ContentType = "application/x-www-form-urlencoded";
strNewValue = Server.HtmlDecode(txtRequest.Value.ToString());
//req.ContentLength = strNewValue.Length;
req.
// Write the request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
// Do the request to get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream() );
strResponse = stIn.ReadToEnd();
stIn.Close();
txtResponse.Value = strResponse;
This works great, thank you. However, I would like to return the actual
status code instead of the public enum HttpStatusCode representation. For
example, I would to see 202 instead of Accepted.
Is this possible?
"Alex Passos" <bz@netmerlin.nospam.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl... Hi Chris,
HttpWebResponse rep = req.GetResponse(); HttpStatusCode c = rep.StatusCode;
when getting the response you may have to deal with exceptions if the request is not successful so wrap it in a try-catch block.
Alex
"Chris Fink" <ch********@gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... How do I retrieve the HTTP Status code (ie 202, 404, etc) below? I am currently receiving the response text but unable to access the response status code.
string strNewValue;
string strResponse;
// Create the request obj
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(txtURL.Text);
// Set values for the request back
req.Method = "POST";
//req.ContentType = "application/x-www-form-urlencoded";
strNewValue = Server.HtmlDecode(txtRequest.Value.ToString());
//req.ContentLength = strNewValue.Length;
req.
// Write the request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
// Do the request to get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream() );
strResponse = stIn.ReadToEnd();
stIn.Close();
txtResponse.Value = strResponse;
I have actually not tried this but I wonder if you can cast the StatusCode
to an integer (or convert via System.Convert). The MSDN docs mention that
each status code maps to a numerical representation of the code: http://msdn.microsoft.com/library/de...classtopic.asp
Alex
"Chris Fink" <ch********@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... This works great, thank you. However, I would like to return the actual status code instead of the public enum HttpStatusCode representation. For example, I would to see 202 instead of Accepted.
Is this possible?
"Alex Passos" <bz@netmerlin.nospam.com> wrote in message news:uT**************@TK2MSFTNGP09.phx.gbl... Hi Chris,
HttpWebResponse rep = req.GetResponse(); HttpStatusCode c = rep.StatusCode;
when getting the response you may have to deal with exceptions if the request is not successful so wrap it in a try-catch block.
Alex
"Chris Fink" <ch********@gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... > How do I retrieve the HTTP Status code (ie 202, 404, etc) below? I am > currently receiving the response text but unable to access the response > status code. > > > string strNewValue; > > string strResponse; > > // Create the request obj > > HttpWebRequest req = (HttpWebRequest) WebRequest.Create(txtURL.Text); > > // Set values for the request back > > req.Method = "POST"; > > //req.ContentType = "application/x-www-form-urlencoded"; > > strNewValue = Server.HtmlDecode(txtRequest.Value.ToString()); > > //req.ContentLength = strNewValue.Length; > > req. > > // Write the request > > StreamWriter stOut = new StreamWriter (req.GetRequestStream(), > System.Text.Encoding.ASCII); > > stOut.Write(strNewValue); > > stOut.Close(); > > // Do the request to get the response > > StreamReader stIn = new > StreamReader(req.GetResponse().GetResponseStream() ); > > strResponse = stIn.ReadToEnd(); > > stIn.Close(); > > txtResponse.Value = strResponse; > >
Alex, thanks again, works like a charm
:)
"Alex Passos" <bz@netmerlin.nospam.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl... I have actually not tried this but I wonder if you can cast the StatusCode to an integer (or convert via System.Convert). The MSDN docs mention that each status code maps to a numerical representation of the code:
http://msdn.microsoft.com/library/de...classtopic.asp Alex
"Chris Fink" <ch********@gmail.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... This works great, thank you. However, I would like to return the actual status code instead of the public enum HttpStatusCode representation.
For example, I would to see 202 instead of Accepted.
Is this possible?
"Alex Passos" <bz@netmerlin.nospam.com> wrote in message news:uT**************@TK2MSFTNGP09.phx.gbl... Hi Chris,
HttpWebResponse rep = req.GetResponse(); HttpStatusCode c = rep.StatusCode;
when getting the response you may have to deal with exceptions if the request is not successful so wrap it in a try-catch block.
Alex
"Chris Fink" <ch********@gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... > How do I retrieve the HTTP Status code (ie 202, 404, etc) below? I
am > currently receiving the response text but unable to access the
response > status code. > > > string strNewValue; > > string strResponse; > > // Create the request obj > > HttpWebRequest req = (HttpWebRequest) WebRequest.Create(txtURL.Text); > > // Set values for the request back > > req.Method = "POST"; > > //req.ContentType = "application/x-www-form-urlencoded"; > > strNewValue = Server.HtmlDecode(txtRequest.Value.ToString()); > > //req.ContentLength = strNewValue.Length; > > req. > > // Write the request > > StreamWriter stOut = new StreamWriter (req.GetRequestStream(), > System.Text.Encoding.ASCII); > > stOut.Write(strNewValue); > > stOut.Close(); > > // Do the request to get the response > > StreamReader stIn = new > StreamReader(req.GetResponse().GetResponseStream() ); > > strResponse = stIn.ReadToEnd(); > > stIn.Close(); > > txtResponse.Value = strResponse; > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jonas Galvez |
last post by:
Hi list, here's a question about urllib. Is it possible to simply
retrieve the HTTP responde code for a given URL? I don't want to
download the body of the HTTP message. I simply want to check the...
|
by: Mazin07 |
last post by:
Is there any way to get the HTTP Response Code sent out by the server
(ie 404, 302, etc)?
Or could I just assume that the same code was sent?
I know the $_SERVER array has a lot of info, but...
|
by: Jon Maz |
last post by:
Hi All,
Here's the code:
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.asdfasdfasdfafsd.com");
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();...
|
by: |
last post by:
Hello All,
I am writing a web application that reads a bitmap from a file and outputing
it to a HTTP response stream to return the image to the requesting client.
The image file is a regular...
|
by: Christina |
last post by:
Hello,
I have an application that HTTP posts a document and is supposed to
receive an http "response code : 400" (or 200... code depends upon the
success/failure) back.
My question is:
1)...
|
by: SimonDev |
last post by:
Hi
I've got an unusual problem I'm hoping someone could advise me on, regarding
the formatting of the body of an HTTP response from a web service.
We are using HTTP POST rather than SOAP for...
|
by: jl |
last post by:
I have a J2ME cell phone application that via the AMS (Application
Manager) delivers a status report to my server indicating whether the
suite was successfully installed and identifying the reason...
|
by: Flip Rayner |
last post by:
I am writing an HTTPHandler that is basically a transparent proxy / URL
Mapper.
I have a line in my code to return a 503:
context.context.Response.StatusCode = ...
|
by: neovantage |
last post by:
Hi geeks,
We made a Java Servlet which takes 3 parameters and upload files from source path to remote path. The three parameters are password, source path and destination path.
When we run this...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |