httpwebrequest

C# HttpWebRequest ignore HTTP 500 error

放肆的年华 提交于 2021-02-04 13:32:47
问题 I'm trying to download a page using the WebRequest class in C#4.0. For some reason this page returns all the content correctly, but with a HTTP 500 internal error code. Request.EndGetResponse(ar); When the page returns HTTP 500 or 404, this method throws a WebException. How can I ignore this? I know it returns 500 but I still want to read the contents of the page / response. 回答1: You can a try / catch block to catch the exception and do additional processing in case of http 404 or 500 errors

C# - Send byte[] as part of json object using HttpWebRequest

二次信任 提交于 2021-01-29 20:12:01
问题 I am trying to send a json object as part of post data to a web api. Some of the json values can be byte[]. Is this at all posiible? If so, how? Here is my code: public static dynamic ExecuteAndReturn(string url, string contentType, string requestType, Dictionary<string, object> parameters) { try { System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); string postData = ""; if (contentType.Contains("json")) postData += "{"; foreach (string key in

C++ interface version of HttpWebRequest and HttpWebResponse

感情迁移 提交于 2021-01-28 09:59:30
问题 We are wondering how to use HttpWebRequest and HttpWebResponse .net framework Class in ATL c++ project is their any interface exposed for webrequest class in C++, currently we cannot have a c# project so we are looking for alternative interface. Any help will be greatly appreciated. Ramanand. 回答1: You have the following options: 1) Write your managed HttpWebRequest code into a C# file, and compile it as a DLL. Use RegAsm.exe to register it as a COM object. Use the COM object from the C/C++

C# send byte[] as JSON to WCF Rest endpoint. 400 Bad Request

自古美人都是妖i 提交于 2021-01-28 05:10:39
问题 I saw below but it adds overhead of encode and decode strings. C# - Send byte[] as part of json object using HttpWebRequest I have a request object like below [DataContract] public class MyRequest { [DataMember] public byte[] SampleByteArray { get; set; } [DataMember] public string UserId { get; set; } } I have below method that returns a byte[] public byte[] SerializeToByteArray<T>(T input) { byte[] byteArray = null; BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream ms = new

How can I Post data using HttpWebRequest?

我的梦境 提交于 2021-01-27 14:02:59
问题 I have this HttpWebRequest : var request = HttpWebRequest.Create("http://example.com/api/Phrase/GetJDTO"); request.ContentType = "application/json"; request.Method = "POST"; But I need to add a payload to the body of the request like this: Jlpt = 2 Can someone help and tell me how I can add data to the POST ? 回答1: You can do by this var request = HttpWebRequest.Create("http://example.com/api/Phrase/GetJDTO"); var postData = "Jlpt = 2"; var data = Encoding.ASCII.GetBytes(postData); request

C#: WebRequest proxy = null side effects

孤街醉人 提交于 2021-01-27 13:05:50
问题 Does anyone know what the side effects are of having a webrequest.proxy = null in a HttpWebRequest? MSDN (.NET Framework 4) says to use GlobalProxySelection.GetEmptyWebProxy() when no proxy should be used. A blank IWebProxy instance will be returned. Visual Studio says it's deprecated!! Does the webrequest in both cases still work if the user's network requires proxy settings? So , what is the correct approach and any known issues/side effects when a proxy is needed? About the deprecated

C#: WebRequest proxy = null side effects

為{幸葍}努か 提交于 2021-01-27 12:56:36
问题 Does anyone know what the side effects are of having a webrequest.proxy = null in a HttpWebRequest? MSDN (.NET Framework 4) says to use GlobalProxySelection.GetEmptyWebProxy() when no proxy should be used. A blank IWebProxy instance will be returned. Visual Studio says it's deprecated!! Does the webrequest in both cases still work if the user's network requires proxy settings? So , what is the correct approach and any known issues/side effects when a proxy is needed? About the deprecated

How to get the SSL key of a https:// C# HttpWebRequest? (similar to browser environment variable SSLKEYLOGFILE)

帅比萌擦擦* 提交于 2021-01-27 06:58:42
问题 Currently I am working on a custom HTTP publisher for the Peach Fuzzing framework. In order to determine if the server responed in an unusual way I need to examine the decrypted incoming / outgoing packages with Wireshark (or the PcapMonitor that is included in the Peach Framework) - to do that I need the SSL keys that are being generated by the C# HttpWebRequest (similar to the content of the SSLKEYLOGFILE) since I am trying to fuzz an SSL protected RESTful webservice. If it is not possible

How To Use HttpWebRequest/Response To Download A Binary (.exe) File From A Web Server?

感情迁移 提交于 2021-01-26 03:43:21
问题 I am writing a program that needs to download an .exe file from a website and then save it to the hard drive. The .exe is stored on my site and it's url is as follows (it's not the real uri just one I made up for the purpose of this question): http://www.mysite.com/calc.exe After many web searches and fumbling through examples here is the code I have come up with so far: HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(http://www.mysite.com/calc.exe); HttpWebResponse webResponse

Discord OAuth Code Usage

孤街浪徒 提交于 2021-01-21 08:26:06
问题 I'm interested in interfacing with Discord using the Discord API. I would describe their documentation as "sparse," but maybe I'm just not looking in the right places. Most of my information comes from this page: https://discordapp.com/developers/docs/topics/oauth2 I've already set up my Discord guild and application (and even a bot, which may be unnecessary). My specific plan to is to allow users to give my site permission to add them to a private Discord guild/server. I have a hyperlink on