httpwebrequest

Setting per request value for ServicePointManager.SecurityProtocol [duplicate]

那年仲夏 提交于 2020-01-01 04:06:07
问题 This question already has answers here : Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request (9 answers) Closed 5 years ago . In c# I am able to set a static value for SSL3 or TLS, e.g. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; Or: ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; But (I believe) this will affect all future HttpWebRequest objects in my application. Is there a way to set this for a given HttpWebRequest or at

Java: How to make a HTTP browsing session

匆匆过客 提交于 2020-01-01 03:42:05
问题 I'm trying to make a Java application that sends some POST requests to a server. The first request is the one with authentication information. Then when I send the next request, I'm getting the answer that my session is expired. But I'm sending the next request within the same second, so, it can't be timed out. So I guess there is something like a HTTP Session in Java, which I need to use for sending my request that way the server knows its following the previous request. I've been searching

calling google Url Shortner API in C#

不打扰是莪最后的温柔 提交于 2020-01-01 03:02:06
问题 I want to call the google url shortner API from my C# Console Application, the request I try to implement is: POST https://www.googleapis.com/urlshortener/v1/url Content-Type: application/json {"longUrl": "http://www.google.com/"} When I try to use this code: using System.Net; using System.Net.Http; using System.IO; and the main method is: static void Main(string[] args) { string s = "http://www.google.com/"; var client = new HttpClient(); // Create the HttpContent for the form to be posted.

C# Xml in Http Post Request Message Body

荒凉一梦 提交于 2019-12-31 21:30:52
问题 I am looking for an example of how, in C#, to put a xml document in the message body of a http request and then parse the response. I've read the documentation but I would just like to see an example if there's one available. Does anyone have a example? thanks 回答1: private static string WebRequestPostData(string url, string postData) { System.Net.WebRequest req = System.Net.WebRequest.Create(url); req.ContentType = "text/xml"; req.Method = "POST"; byte[] bytes = System.Text.Encoding.ASCII

HttpWebRequest.GetRequestStream : What it does?

纵然是瞬间 提交于 2019-12-31 08:11:17
问题 Code exemple: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://some.existing.url"); request.Method = "POST"; request.ContentType = "text/xml"; Byte[] documentBytes = GetDocumentBytes (); using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(documentBytes, 0, documentBytes.Length); requestStream.Flush(); requestStream.Close(); } When I do request.GetRequestStream () , there's nothing to send in the request. From the name of the method, and the

Automate picture downloads from website with authentication

天涯浪子 提交于 2019-12-31 03:24:08
问题 My intention is to automate the downloading of all pictures in a website that requires a login (a web-form based login I think) The website: http://www.cgwallpapers.com The login url: http://www.cgwallpapers.com/login.php The registered members url: http://www.cgwallpapers.com/members A random wallpaper url that is only accesible and downloadable for registered members: http://www.cgwallpapers.com/members/viewwallpaper.php?id=1764&res=1920x1080 Knowing that the viewwallpaper.php post data

HttpWebRequest Won't Serialize

空扰寡人 提交于 2019-12-31 02:55:11
问题 I'm getting the following error when I try to Serialize an HttpWebRequest Type 'System.Net.KnownHttpVerb' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. Using .Net Framework 2.0 This is one of the properties that my class holds. It's a requirement to serialize it. HttpWebRequest is marked as Serializable so it supposed to Serialize 回答1: Well, if one of the contained objects is marked as non-serializable, I believe you're

HttpWebRequest FileUpload causes OutOfMemoryException

只愿长相守 提交于 2019-12-31 02:54:06
问题 I always get this OutOfMemoryException : System.OutOfMemoryException was not handled. Message=Exception of type 'System.OutOfMemoryException' was thrown. Source=System StackTrace: at System.Net.ScatterGatherBuffers.AllocateMemoryChunk(Int32 newSize) at System.Net.ScatterGatherBuffers.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) at System.Net.ConnectStream

How To Set useUnsafeHeaderParsing For .NET Compact Framework

非 Y 不嫁゛ 提交于 2019-12-31 02:26:27
问题 In my Windows CE 6.0 app, I am communicating with a proprietary web server device that is returning bad header information (more specifically, it's returning NO header information). I believe this lack of header information is the reason why my HttpWebRequest methods are not working properly. I recall that the .NET "regular" Framework allows for us to programmatically configure the System.Net.Configuration assembly to allow for invalid headers (useUnsafeHeaderParsing). Unfortunately, for me,

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

荒凉一梦 提交于 2019-12-30 11:11:17
问题 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