httpwebrequest

C# .NET Uploading file to a web form using HttpWebRequest

不羁岁月 提交于 2019-12-30 11:07:36
问题 Does anyone have a working example using HttpWebRequest in C# to submit a file from the local drive to a multipart/form-data web form? 回答1: it is WAY easier to do this with WebClient string url = "http://myserver/myapp/upload.aspx"; string file = "c:\\files\\test.jpg"; WebClient wc = new WebClient(); wc.UploadFile(url,"post",file); If it needs to be httpwebrequest I can put something together for you (it is possible), but it will be more like 50 lines then 5 来源: https://stackoverflow.com

including login credentials with a WebRequest

烂漫一生 提交于 2019-12-30 07:11:26
问题 I am trying to "behind the scenes" log myself into a website, from the VB code behind my ASP.NET website. But I am dumbfounded as to how to do this. As far as I know I should be using the WebRequest or Webclient class. That is about as much as I know. I am not sure how to use the class. I want to click a button on my website and have its Click event send a username and password to another website. This other site isot affiliated with mine. I realize the concept may seem stupid, but I plan on

Anyone have sample code for doing a “chunked” HTTP streaming download of one web directly to a upload to a separate web server?

无人久伴 提交于 2019-12-30 06:53:10
问题 Background - I'm trying to stream an existing webpage to a separate web application, using HttpWebRequest/HttpWebResponse in C#. One issue I'm striking is that I'm trying to set the file upload request content-length using the file download's content-length, HOWEVER the issue seems to be when the source webpage is on a webserver for which the HttpWebResponse doesn't provide a content length. HttpWebRequest downloadRequest = WebRequest.Create(new Uri("downloaduri")) as HttpWebRequest; using

HttpWebRequest NameResolutionFailure exception in .NET (with Mono on Ubuntu)

旧街凉风 提交于 2019-12-30 03:56:06
问题 I have a .NET program running on Ubuntu via Mono 2.10 The program downloads a webpage via an HttpWebRequest every minute or so which works fine most of the time: String result; WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); using (objResponse = objRequest.GetResponse()) { using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } } The problem is that after

How to login to wordpress programmatically?

落爺英雄遲暮 提交于 2019-12-29 14:58:34
问题 I need to perform some action in wordpress admin panel programmatically but can't manage how to login to Wordpress using C# and HttpWebRequest. Here is what I do: private void button1_Click(object sender, EventArgs e) { string url = "http://localhost/wordpress/wp-login.php"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); CookieContainer cookies = new CookieContainer(); SetupRequest(url, request, cookies); //request.Accept = "text/html,application/xhtml+xml,application/xml;q

Cannot get cookies in wp7 using HttpWebRequest

只愿长相守 提交于 2019-12-29 09:22:33
问题 I'm trying to save cookies in a post request. Here is my code : CookieContainer myCookieContainer = new CookieContainer(); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; myHttpWebRequest.UserAgent = userAgent; myHttpWebRequest.CookieContainer = myCookieContainer; myHttpWebRequest.Method = "POST"; byte[] postdata = encoding.GetBytes(submitString); myHttpWebRequest.BeginGetRequestStream(async1 => {

Cannot get cookies in wp7 using HttpWebRequest

≡放荡痞女 提交于 2019-12-29 09:22:11
问题 I'm trying to save cookies in a post request. Here is my code : CookieContainer myCookieContainer = new CookieContainer(); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; myHttpWebRequest.UserAgent = userAgent; myHttpWebRequest.CookieContainer = myCookieContainer; myHttpWebRequest.Method = "POST"; byte[] postdata = encoding.GetBytes(submitString); myHttpWebRequest.BeginGetRequestStream(async1 => {

Async and Await with HttpWebRequest.GetResponseAsync

只谈情不闲聊 提交于 2019-12-29 06:40:23
问题 I am trying to use Async and Await when making a web request and am finding that it never gets past the await line. I am doing this from a Metro app, but I also verified the problem in a winforms app. public async Task<string> DoSomething() { string url = "http://imgur.com/gallery/VcBfl.json"; HttpWebRequest request = HttpWebRequest.CreateHttp(url); var ws = await request.GetResponseAsync(); return ws.ResponseUri.ToString(); ; } If I don't use await and instead perform a synchronous wait, it

Async and Await with HttpWebRequest.GetResponseAsync

删除回忆录丶 提交于 2019-12-29 06:40:11
问题 I am trying to use Async and Await when making a web request and am finding that it never gets past the await line. I am doing this from a Metro app, but I also verified the problem in a winforms app. public async Task<string> DoSomething() { string url = "http://imgur.com/gallery/VcBfl.json"; HttpWebRequest request = HttpWebRequest.CreateHttp(url); var ws = await request.GetResponseAsync(); return ws.ResponseUri.ToString(); ; } If I don't use await and instead perform a synchronous wait, it

HttpWebRequest with https in C#

强颜欢笑 提交于 2019-12-29 03:33:29
问题 This piece of code doesn't work; it's logging in into website which is using https protocol. How to solve this problem? The code stops at GetRequestStream() anytime anywhere saying that protocol violation exception is unhandled.. string username = "user"; string password = "pass"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://moje.azet.sk/prihlasenie.phtml?KDE=www.azet.sk%2Findex.phtml%3F"); request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR