webrequest

Uploading an image using C# and WebRequest?

◇◆丶佛笑我妖孽 提交于 2019-12-17 20:39:52
问题 Here is the working code in Python (using cURL): #!/usr/bin/python import pycurl c = pycurl.Curl() values = [ ("key", "YOUR_API_KEY"), ("image", (c.FORM_FILE, "file.png"))] # OR: ("image", "http://example.com/example.jpg"))] # OR: ("image", "BASE64_ENCODED_STRING"))] c.setopt(c.URL, "http://imgur.com/api/upload.xml") c.setopt(c.HTTPPOST, values) c.perform() c.close() Here's what I have in C#: public void UploadImage() { //I think this line is doing something wrong. //byte[] x = File

CHROME WebRequest APIs example error: “onBeforeRequest” can only be used in extension processes

假装没事ソ 提交于 2019-12-17 19:51:43
问题 I try to test a example of WebRequest APIs, but throw error: "onBeforeRequest" can only be used in extension processes. manifest.json: { "name": "example", "version": "1.0", "permissions": [ "experimental", "http://*/*", "https://*/*" ], "content_scripts": [ { "js": [ "foo.js" ], "matches": [ "http://*/*", "https://*/*" ], "run_at": "document_start" } ] } foo.js is exactly the example 1 回答1: Chrome extension functions (which includes the webRequest API) cannot be used in content scripts ( foo

Forcing Basic Authentication in WebRequest

核能气质少年 提交于 2019-12-17 10:27:25
问题 I am integrating web service that will use an HTTP-POST to request and retrieve data. The remote server requires basic authentication as per RFC 2617 My attempts to authenticate are failing. It fails in that, even though I attach a 'NetworkCredential' object to the 'Credentials' property of a 'HttpWebRequest' object, no authentication information is sent in the header, even if I set 'PreAuthenticate' = true. What am I missing? //chunk used NetworkCredential netCredential = new

Test if a website is alive from a C# application

≯℡__Kan透↙ 提交于 2019-12-17 05:40:46
问题 I am looking for the best way to test if a website is alive from a C# application. Background My application consists of a Winforms UI , a backend WCF service and a website to publish content to the UI and other consumers. To prevent the situation where the UI starts up and fails to work properly because of a missing WCF service or website being down I have added an app startup check to ensure that all everything is alive. The application is being written in C#, .NET 3.5, Visual Studio 2008

WebRequest not returning HTML

一世执手 提交于 2019-12-14 03:37:36
问题 I want to load this http://www.yellowpages.ae/categories-by-alphabet/h.html url, but it returns null In some question I have heard about adding Cookie container but it is already there in my code. var MainUrl = "http://www.yellowpages.ae/categories-by-alphabet/h.html"; HtmlWeb web = new HtmlWeb(); web.PreRequest += request => { request.CookieContainer = new System.Net.CookieContainer(); return true; }; web.CacheOnly = false; var doc = web.Load(MainUrl); the website opens perfectly fine in

WebRequest NameResolutionFailure

送分小仙女□ 提交于 2019-12-14 02:16:37
问题 I'm attempting to write a small screen-scraping tool for statistics aggregation in c#. I have attempted to use this code, (posted many times here but again for detail): public static string GetPage(string url) { HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; WebResponse response = (HttpWebResponse) request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new

Why does this WebRequest to sony.com throw an exception?

落爺英雄遲暮 提交于 2019-12-13 18:16:18
问题 My goal is to write a C# method that validates if a url points to a valid online resource. It currently looks something like this: string url = "http://www.sony.com/"; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "HEAD"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { var msg = response.StatusCode == HttpStatusCode.OK ? "OK" : "Dead Link"; Console.WriteLine(msg); } This code throws an exception, even though I can browse to

How to change directory permissions/chmod on FTP server using FtpWebRequest/WebRequest (C#)?

て烟熏妆下的殇ゞ 提交于 2019-12-13 16:32:37
问题 How to change directory permissions on FTP server using FtpWebRequest/WebRequest (C#)? I've tried this, but without success (ftp unsupported method exception): ftpPath = ftpPath.Replace(dirname, ""); var request = (FtpWebRequest)WebRequest.Create(ftpPath); request.Credentials = new NetworkCredential(config.FtpUser, config.FtpPassword); request.UsePassive = true; request.UseBinary = true; request.Method = "CHMOD 777 " + dirname; using (var resp = (FtpWebResponse)request.GetResponse()) Any

WebRequest Async CallBack Code only gets call the first time

十年热恋 提交于 2019-12-13 03:44:55
问题 I am an absolute beginner on ASP.net (VB.) Please pardon me if the question is too obvious for the experienced members. I tried to make a simple WebRequest in the async mode in case the target URL takes long to provide the data. In my code below, I just want to see if the callback block (RespCallback) is called correctly every time. If all goes well, lblResult should have the string '123' appended to it every time I click the button which calls the 'GetData' sub. However, the lblResult only

c# - programmatically form fill and submit login

拈花ヽ惹草 提交于 2019-12-13 03:43:13
问题 Using C# and ASP.NET I want to programmatically fill in values for a web form and then 'POST' those values. I've seen examples of others using webclient and other classes in posts such as: How do you programmatically fill in a form and 'POST' a web page? I am looking to carry out similar functionality - where I automatically post data to a form. In my case I am looking to submit data to simulate a login. I have a couple of questions: 1) Using the Post code in this thread, how can you