httpwebresponse

HttpWebResponse get stuck while running in a loop

荒凉一梦 提交于 2020-02-14 09:21:16
问题 I build this method (c#) in order to receive the HTTP response status code from an URL. whene I run this method ones it's works fine, but when I run it in a loop, the third time its stuck. any clue?? public static string isAlive(string url) { Console.WriteLine("start: Is Alive Test"); WebRequest request = WebRequest.Create(url); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); return Convert.ToString((int)response.StatusCode); } catch(WebException ex) { HttpWebResponse

HttpWebResponse get stuck while running in a loop

人盡茶涼 提交于 2020-02-14 09:20:23
问题 I build this method (c#) in order to receive the HTTP response status code from an URL. whene I run this method ones it's works fine, but when I run it in a loop, the third time its stuck. any clue?? public static string isAlive(string url) { Console.WriteLine("start: Is Alive Test"); WebRequest request = WebRequest.Create(url); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); return Convert.ToString((int)response.StatusCode); } catch(WebException ex) { HttpWebResponse

Garbled httpWebResponse string when posting data to web form programmatically

Deadly 提交于 2020-01-30 08:28:47
问题 I tried to search previous discussion about this issue but I didn't find one, maybe it's because I didn't use right keywords. I am writing a small program which posts data to a webpage and gets the response. The site I'm posting data to does not provide an API. After some Googling I came up to the use of HttpWebRequest and HttpWebResponse. The code looks like this: HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("https://www.site.com/index.aspx"); CookieContainer cookie = new

Garbled httpWebResponse string when posting data to web form programmatically

回眸只為那壹抹淺笑 提交于 2020-01-30 08:27:09
问题 I tried to search previous discussion about this issue but I didn't find one, maybe it's because I didn't use right keywords. I am writing a small program which posts data to a webpage and gets the response. The site I'm posting data to does not provide an API. After some Googling I came up to the use of HttpWebRequest and HttpWebResponse. The code looks like this: HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("https://www.site.com/index.aspx"); CookieContainer cookie = new

Optimal buffer size for response stream of HttpWebResponse

情到浓时终转凉″ 提交于 2020-01-24 02:23:46
问题 What's the optimal buffer size to use with a stream from HttpWebResponse.GetResponseStream()? Online examples vary from 256b to as much as 5Kb. What gives? I guess buffer sizes might be situational. If so what are the situations to use what type of buffer size? Thanks. 回答1: Really, it doesn't matter very much. Sure, if you use really small buffers, you may have to make a few extra calls down through the layers to get the bytes (though the stream is likely doing at least some buffering -- I

Optimal buffer size for response stream of HttpWebResponse

不羁的心 提交于 2020-01-24 02:23:27
问题 What's the optimal buffer size to use with a stream from HttpWebResponse.GetResponseStream()? Online examples vary from 256b to as much as 5Kb. What gives? I guess buffer sizes might be situational. If so what are the situations to use what type of buffer size? Thanks. 回答1: Really, it doesn't matter very much. Sure, if you use really small buffers, you may have to make a few extra calls down through the layers to get the bytes (though the stream is likely doing at least some buffering -- I

HttpWebRequest and HttpWebResponse : maintaining state of logged in request for consecutive queries

*爱你&永不变心* 提交于 2020-01-22 15:27:28
问题 I have a few HttpWebRequests and HttpWebResponses chained together, also using CookieContainer. The code simulates a user going through three different 'I agree' pages which set the cookie info, logging in with username and password on a fourth, and doing a POST (search) on the fifth returning the response as a string. Is there a way I can maintain the HttpWebRequest object as 'logged in' to avoid going through those steps each time any user performs a search? Can I set it up as static, and

HttpWebRequest and HttpWebResponse : maintaining state of logged in request for consecutive queries

你离开我真会死。 提交于 2020-01-22 15:27:06
问题 I have a few HttpWebRequests and HttpWebResponses chained together, also using CookieContainer. The code simulates a user going through three different 'I agree' pages which set the cookie info, logging in with username and password on a fourth, and doing a POST (search) on the fifth returning the response as a string. Is there a way I can maintain the HttpWebRequest object as 'logged in' to avoid going through those steps each time any user performs a search? Can I set it up as static, and

WebResource multipart post request

五迷三道 提交于 2020-01-07 03:07:19
问题 I need to send post request using java test to this rest function : @RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody String handleFileUpload(@PathVariable Long ownerId, @RequestBody MultipartFile file, HttpServletResponse response) throws IOException { //Some function } this is my trial: File file = new File("filePath"); FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE); WebResource webResource =

HttpWebRequest and HttpWebResponse in C#

给你一囗甜甜゛ 提交于 2020-01-06 11:48:55
问题 How to use HttpWebRequest and HttpWebResponse to create a webservice and how will the request and responses will be send across the wire? 回答1: this is the syntax for using HttpWebRequest and HttpWebResponse WebRequest _request; string text; string url = "UrlToGet"; _request = (HttpWebRequest)WebRequest.Create(url); using (WebResponse response = _request.GetResponse()) { using (StreamReader reader =new StreamReader(response.GetResponseStream())) { text = reader.ReadToEnd(); } } 回答2: