webrequest

What makes this HTTPS WebRequest time out even though it works in the browser?

时间秒杀一切 提交于 2019-11-27 18:50:27
Here's my request: var request = (HttpWebRequest) WebRequest.Create("https://mtgox.com/"); request.CookieContainer = new CookieContainer(); request.AllowAutoRedirect = false; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate"; request.Headers[HttpRequestHeader.AcceptLanguage] = "en-gb,en;q=0.5"; request.Headers[HttpRequestHeader.AcceptCharset] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"; request.Timeout = 5000; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0";

Upload a file to an FTP server from a string or stream

老子叫甜甜 提交于 2019-11-27 18:34:36
问题 I'm trying to create a file on an FTP server, but all I have is either a string or a stream of the data and the filename it should be created with. Is there a way to create the file on the server (I don't have permission to create local files) from a stream or string? string location = "ftp://xxx.xxx.xxx.xxx:21/TestLocation/Test.csv"; WebRequest ftpRequest = WebRequest.Create(location); ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpRequest.Credentials = new NetworkCredential

Java/Android: java.lang.OutOfMemoryError while building a JSON object

ε祈祈猫儿з 提交于 2019-11-27 18:15:16
问题 I am importing JSON data from a public database URI http://data.seattle.gov/api/views/3k2p-39jp/rows.json and the rows go as far as 445454. Using the following code I am constructing the JSON object of the entire data. HttpGet get = new HttpGet(uri); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(get); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder=new StringBuilder();

Multithreading a large number of web requests in c#

大兔子大兔子 提交于 2019-11-27 17:37:53
I have an program where I need to create some large number of folders to an external sharepoint site (external meaning I can't use the sharepoint object model). Web requests work well for this, but simply doing them one at a time (send request, wait for response, repeat) is rather slow. I decided to multithread the requests, to try and speed it up. The program has sped up considerably, but after some amount of time (between 1-2 minutes or so), concurrency exceptions start getting thrown. Code is below, is this the best way to go about this? Semaphore Lock = new Semaphore(10, 10); List<string>

How to force WebRequest to send Authorization header during POST

时光毁灭记忆、已成空白 提交于 2019-11-27 17:30:10
问题 When using WebRequest to send a POST, the Authorization header is not sent with the request even though I have manually set the header and set PreAuthenticate to true, eg: webRequest.Headers["Authorization"] = "OAuth oauth_consumer_key=bFPD..."; webRequest.PreAuthenticate = true; Using Fiddler I can see that the Authorization header is not sent. The target site (Twitter) returns a 400 (Bad request) rather than a 401 (Not authorized) which is therefore the incorrect challenge required for

c# WebRequest using WebBrowser cookie

余生颓废 提交于 2019-11-27 14:26:42
I am logging into a site using a WebBrowser, then i want use regex to get some data , but webRequest didnt use web Browse cookie , my webBrowser is in public , is there any way to using WebBrowser cookie in webRequest ? public CookieContainer GetCookieContainer() { CookieContainer container = new CookieContainer(); foreach (string cookie in webBrowser1.Document.Cookie.Split(';')) { string name = cookie.Split('=')[0]; string value = cookie.Substring(name.Length + 1); string path = "/"; string domain = ".google.com"; //change to your domain name container.Add(new Cookie(name.Trim(), value.Trim()

C# Getting proxy settings from Internet Explorer

给你一囗甜甜゛ 提交于 2019-11-27 13:16:00
问题 i have a problem in certain company in germany. They use proxy in their network and my program cant communicate with server. IE works with this settings: It means: Automatically detect settings This is the code: public static bool CompleteValidation(string regKey) { string uri = "***"; int c = 1; if (Counter < 5) c = 6 - Counter; string response = ""; try { System.Net.ServicePointManager.Expect100Continue = false; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request

Forcing Basic Authentication in WebRequest

天涯浪子 提交于 2019-11-27 11:18:32
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 NetworkCredential(" uid", "pwd"); Uri uri = new Uri("http://address of services"); ICredentials credentials =

How to get json response using system.net.webrequest in c#?

梦想的初衷 提交于 2019-11-27 09:22:58
问题 I need to get json data from an external domain. I used webrequest to get the response from a website. Here's the code: var request = WebRequest.Create(url); string text; var response = (HttpWebResponse) request.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); } Anyone know why I can't get the json data? 回答1: You need to explicitly ask for the content type. Add this line: request.ContentType = "application/json; charset=utf-8"; At the

How do you send an HTTP Get Web Request in Python? [duplicate]

微笑、不失礼 提交于 2019-11-27 09:20:44
问题 This question already has an answer here: What is the quickest way to HTTP GET in Python? 11 answers I am having trouble sending data to a website and getting a response in Python. I have seen similar questions, but none of them seem to accomplish what I am aiming for. This is my C# code I'm trying to port to Python: static void Request(Uri selectedUri) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(selectedUri); request.ServicePoint.BindIPEndPointDelegate =