.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Get filename HttpWebRequest

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :.NET Framework
I'm downloading some files with HTTPRequest, following this tutorial http://www.geekpedia.com/tutorial179_Creating-a-download-manager-in-Csharp.html However, how do I get the filename? I need to get the file name in order to save it, because I don't know the extensions of the files.   PS: I asked this question in the wrong place : http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f3be4bbb-8025-4b1f-a2dd-b1b70b071bc7 Sorry to ask again here (in the right place)Get a life. Go party!

View Complete Post

More Related Resource Links



Ive 'inherited' some code that creates a HttpWebRequest object to consume a webservice and am working through it to figure out what each bit does.  Ive never consumed webservices this way before (I always create a webreference) so this way of working is new to me.  I can follow all of it except for one bit.  Heres the code Im having trouble understanding

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytesToWrite = encoding.GetBytes("The message here");

// create web request
const string Action = "http://Awebaddress.org/AProcess"; 
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("The web service url here");

const string contentType = "text/xml; charset=utf-8";
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
httpWebRequest.Timeout = -1;
httpWebRequest.ContentLength = bytesToWrite.Length;

the line im having trouble with is this one

Adding a cookie to a response.redirect vs. httpWebRequest


Hello, I will try to be as clear as I can be.  I'm sure this question has been asked but I can't find a suitable answer for this particular situation.

I need to be able to redirect the browser to a new 3rd party page while at the same time supplying a cookie required for some form of authentication on the 3rd party site.

I have managed to get this to work in the following manner:


'SessionID is predetermined by another HttpWebRequest/Response  

Dim sessionCookie As New Cookie("ezproxy", sessionID.Substring(1), "/", ".someother.site")

Dim CookieJar As New CookieContainer


rRequest = HttpWebRequest.Create("where I want to go")

rRequest.CookieContainer = CookieJar

rRequest.Method = "GET"


'Make the request and get the response.

rResponse = rRequest.GetResponse()


'Save cookie(s)

If (rResponse.Cookies.Count <> 0) Then

For Each cook

need help about "Unable to connect to remote server." using HttpWebRequest


Hello friends 
I am creating an application where I want to store an html page from one of my websites into another web site. 
For the same purpose I am taking the url of the html pages 
for example if I want to copy this page "http://mydomain.com/html/page1.html" then i take this url from a text box which user enters.

need help about HttpWebRequest : A connection attempt failed because the connected party did not pro



I am creating an application for bulk mailing. Its on my subdomain. 

The functionality i require here is I need to copy an html file located in different subdomains on my production server to my bulk mailing application. 

I am using HttpWebRequest for the purpose where I take the url of the page into a text box and create a HttpWebrRequest. 

The code is as simple as follows.

HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://mydomainorsubdomain.com/dir1/page.html");

and this is working fine on my local development environment that is in VS2010 

but when i put code to production server it is throwing following error. 

2010-08-25 15:21:00,845 ERROR Error caught : the details of the error are  System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketIn



Im using the HttpWebRequest class to consume a webservice that has 3 input parameters. I cant figure out how to pass in the 3 parameters.

I can pass in 1 parameter like this

byte[] bytesToWrite = encoding.GetBytes(MessageXml);

Stream newStream = httpWebRequest.GetRequestStream();
                newStream.Write(bytesToWrite, 0, bytesToWrite.Length);
Stream newStream = httpWebRequest.GetRequestStream();
newStream.Write(bytesToWrite, 0, bytesToWrite.Length);

can anyone give me some help in modifying this approach to handle 3 input parameters ?

calling WCF service Method in HTTP GET by browser or ASP.NET ( like HttpWebRequest for example)

Can i call a WCF service Method using HTTP GET by browser or ASP.NET (without WCF Client)? it can be done with asmx web service.... but i can't find a way to call a WCF service Method with HTTP GET through the browser or C# ASP.NET Code... can i do that ?

Working on httpwebrequest

Hi guys, I need your help. I can't find the source for the httpwebrequest method which allows me to connect to the proxy server? And I also can't find the source to detect whether if the proxy is a fbi or governments local computers?   Any info would be much appreicate.   Thanks, Mark

HttpWebRequest and Siteminder

Hi I am creating a console application for server monitoring.Application uses 'SiteMinder' for authentication.I want to login to the application by sending data programatically by using HttpWebRequest.Even if I am sending required data to the page, it is getting re-directed to the siteminder login screen. (I have used Fiddler to see the xact data that gets send to the server.)Can I know any link where I can find Siteminder + HttpWebUrl examples?Regards,Neeraj.

sending xml inside a soap request with HttpWebRequest

Im trying to send some xml inside a soap request to a webservice using the HttpWebRequest class.  I know this isnt the best way, but my hands are tied by company policy so i have to do it this way.  My webmethod has an input parameter  "SourceXML"  so my soap request has this node<SourceXML></SourceXML>I need to insert the xml in this node but whenver I insert it and try to send it to my web method I get an error "400 bad request"Is this even possible ?  I need to insert the xml as a string literal and read it in the web methodStringBuilder sb = new StringBuilder(_soapEnv); -- soap enevlope template containing the SourceXML node sb.Insert(sb.ToString().IndexOf("</SourceXML>"), the xml I want to insert in the node); sendmessage(url, webmethod, sb.ToString()) -- send the message to the webserviceIf I put plain text in the string builderegsb.Insert(sb.ToString().IndexOf("</SourceXML>"), "this is a test");everything works ok, but as soon as i put some xml in it fails. Am I going about this in the right way ?basically my webmethod will have 2 input parameters, some xml and an object, but I just cant get it to work. Can anyone help ?

filename without directory

how to insert the exact  filename to the database without getting the full directory like c://something/something/filename  into the column 'Filename'     waitng for reply

Capture the xml filename and load in a table

Hey I am having folder which contains multiple xml files.Now I need to read the xml file name and write in a table. I follwed the steps which are in the following link. http://www.sqlservercentral.com/articles/SSIS/67871/ But I am getting data as well as. I need only the file name to be written in a table.

Odd hitch using HTTPWebRequest object

I'm running on ASP.NET 2.0I'm having an issue with the HTTPWebRequest object (or any object that tries to return data from external sources). For some reason the first time it runs it takes an additional 5-10 seconds to connect to a web site. After that it is instant as long as the app is re-connecting.If you wait a little while without connecting (maybe a minute or so) the 5-10 second hitch rears its ugly head again. This happens consistently no matter what site I am polling, or what method I am using to connect to the site (or whether I'm using c# or classic asp for that matter). On our previous server, running the exact same code, the hitch didn't exist.Are there any obvious settings I should be looking for?

Local Cookies Storage, HttpWebRequest and HttpWebResponse

How to work with it? How way to place cookies retrieved from HttpWebResponse to the local Cookies storage? Please show me example

HTTPWebRequest and XML

Hi All,            I have an application that reads the xml from a url(queue) using HTTPWebRequest and puts the data received to a database table. Once the xml is read from the url it will no longer be queued in the url. I am able to complete the operation successfully. This is an application with windows timer with a delay of one minute. When the number of xmls to be read from the url is more, the application produces a lot of delay.How can I increase the speed of the operation? Or how can run multiple instances of the same application. Regards, Zamsheer

HttpWebRequest Form Authentication Not Getting Past Login Page

Hey Guys,I am trying to use HTTPWebRequest to login to a site and then retrieve the page after login. However, it seems as if I can't get past the login. I also investigated with Fiddler and tried mimicking Fiddler almost completely and still no luck.Any idea what I am doing wrong?Thanks,Mohammed    Dim webRequest As HttpWebRequest Dim responseReader As StreamReader Dim responseData As String Dim postData As String = "login=testexpert@yahoo.com&password=testexpert" Dim cookies As CookieContainer = New CookieContainer() Dim requestWriter As StreamWriter Try 'post form data to page strUrl = "https://www.ideeli.com/login" webRequest = HttpWebRequest.Create(strUrl) webRequest.Method = WebRequestMethods.Http.Post webRequest.ContentType = "application/x-www-form-urlencoded" webRequest.CookieContainer = cookies webRequest.ContentLength = postData.Length requestWriter = New StreamWriter(webRequest.GetRequestStream) requestWriter.Write(postData) requestWriter.Close() 'recieve cookie webRequest.GetResponse().Close() 'now we send the cookie webRequest = HttpWebRequest.Create("http://www.ideeli.com") webRequest.CookieContainer = cookies responseReader = New StreamReader(webRequest.GetResponse.GetResponseStream()) responseData = responseReader.ReadToEnd() res

HttpWebRequest NTLM auth to secure server only works in .NET 4

Hi, I am trying to connect to a secure server via a proxy server which requires NTLM authentication, somewhat similar to http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/a4aba6c5-6180-441e-ab60-95347fcdc051 The test app below fails with a 407 error when target framework is set to .NET 2, 3, or 3.5, but succeeds w/ .NET 4: static void Main(string[] args) { WebProxy myProxy = new WebProxy(); myProxy.Address = new Uri("http://testproxy.here.com:3121"); myProxy.Credentials = new NetworkCredential("proxyuser", "password", "testproxy.here.com"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://testserver.here.com/sessions")); request.Method = WebRequestMethods.Http.Post; request.ProtocolVersion = new Version("1.1"); request.Credentials = new NetworkCredential("username", "password"); request.Proxy = myProxy; allDone.Reset(); request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); allDone.WaitOne(); } private static void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest httpWebRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse httpWebResponse = null; try { if (httpWebRequest.HaveResponse == true) { httpWebResponse = (Htt

create a server request using with httpwebrequest

Hi guys, I have create a project with four textbox, first one are for ip address, second one are for the open ports, the third one are for username and last one is for the password. So, if I use httpwebrequest, is it possible to connect to vpn server??   Thanks, Mark
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend