webrequest

How to set User Agent with System.Net.WebRequest in c#

久未见 提交于 2019-11-29 18:04:45
问题 Hi I'm trying to set User Agent with WebRequest, but unfortunately I've only found how to do it using HttpWebRequest, so here is my code and I hope you can help me to set the User Agent using WebRequest. here is my code public string Post(string url, string Post, string Header, string Value) { string str_ReturnValue = ""; WebRequest request = WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; request.Timeout = 1000000; if (Header != null &

ASP.NET Multithreading Web Requests

爱⌒轻易说出口 提交于 2019-11-29 14:12:45
问题 I'm building a page in my ASP.NET solution that retrieves most of its data from a 3rd Party API Service. The page itself will need to make approximately 5 individual different calls to the API to populate all of its controls, as each Web Request to the API brings back different sets of Data. I would like to deal with each separate Web request i make on a new thread, simultaneously so that load time is reduced. Each request I'm making looks like this :- WebRequest request = WebRequest.Create

Downloading pdf file using WebRequests

筅森魡賤 提交于 2019-11-29 14:10:31
问题 I'm trying to download a number of pdf files automagically given a list of urls. Here's the code I have: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; var encoding = new UTF8Encoding(); request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-gb,en;q=0.5"); request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.UserAgent = "Mozilla/5.0

c# Webrequest Post and GetResponse

喜欢而已 提交于 2019-11-29 11:42:16
I am writing a program that will submit a XML to a website. The code written works fine, but sometimes it just stops working for some reason, throwing a System.Net.ProtocolViolationException. I can close the program and re-run - it starts working again just fine. Here is the code that I am using: private string Summit(string xml) { string result = string.Empty; StringBuilder sb = new StringBuilder(); try { WebRequest request = WebRequest.Create(this.targetUrl); request.Timeout = 800 * 1000; RequestState requestState = new RequestState(xml); requestState.Request = request; request.ContentType =

Monotouch: WebRequest connection fails after switching off Airplane Mode on iPhone

∥☆過路亽.° 提交于 2019-11-29 10:24:29
问题 My monotouch app is doing periodic background synchronization with a web-service. It runs perfectly and detects Airplane mode correctly. When I switch off WiFi, it automatically starts using the WWAN (GPRS, 3G) connection. So far I'm very satisfied, but... After switching off Airplan Mode there is no way my app will reconnect when there is no WiFi available. It detects correctly using a NetworkReachability object that WWAN is available and that a connection is required. But the first try

How do I programmatically send information to a web service in C# with .NET?

耗尽温柔 提交于 2019-11-29 09:36:44
问题 I know this sort of counts as reinventing the wheel here, but I need to know to communicate with a web service through http/soap/xml and web messages. The reason is I need to communicate with a third party web service for work, but there is something wrong with the WSDL or something and it does not work when connecting to it with the .NET wizard. So, can anyone give me a process/simple example/etc. of how to do this or can anyone give me a link to somewhere that explains it? I'm not very

Sending POST data with C#

喜夏-厌秋 提交于 2019-11-29 07:54:05
This is the method that I'm trying to use to send POST data to a URL and bring back its response: public string sendPOST(string URL, string postData) { byte[] byteArray; Stream webpageStream; StreamReader webpageReader; String webpageContent; byteArray = Encoding.UTF8.GetBytes(postData); _webRequest = WebRequest.Create(URL); _webRequest.Method = "POST"; _webRequest.ContentType = "application/x-www-form-urlencoded"; _webRequest.ContentLength = byteArray.Length; webpageStream = _webRequest.GetResponse().GetResponseStream(); webpageStream.Write(byteArray, 0, byteArray.Length); webpageStream.Close

How to send a POST with a JSON in a WebRequest() call using MQL4?

♀尐吖头ヾ 提交于 2019-11-29 07:51:07
I would like to send a POST from MQL4 -script, using a JSON-format to a Node-server. I've tried the webRequest() standard function in MQL4 , based on the following documentation, but it did NOT success. From MQL4 Documentation: Sending simple requests of type "key=value" using the header `Content-Type: application/x-www-form-urlencoded`. int WebRequest( const string method, // HTTP method const string url, // URL const string cookie, // cookie const string referer, // referer int timeout, // timeout const char &data[], // the array of the HTTP message body int data_size, // data[] array size

How to get website title from c#

為{幸葍}努か 提交于 2019-11-29 07:35:07
问题 I'm revisiting som old code of mine and have stumbled upon a method for getting the title of a website based on its url. It's not really what you would call a stable method as it often fails to produce a result and sometimes even produces incorrect results. Also, sometimes it fails to show some of the characters from the title as they are of an alternative encoding. Does anyone have suggestions for improvements over this old version? public static string SuggestTitle(string url, int timeout)

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

江枫思渺然 提交于 2019-11-29 04:47:19
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(userName, password); string data = csv.getData(); MemoryStream stream = csv.getStream(); //Magic using (var