httpwebresponse

How to create a request to a URL and write the response to the page

杀马特。学长 韩版系。学妹 提交于 2019-12-04 17:29:48
I believe I've done this before, but I can't seem to remember how:( HttpWebRequest request = (HttpWebRequest)WebRequest.Create("www.example.com"); request.Method = "GET"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); How do I then write the response to the page? Thanks a lot. The below example demonstrates how it can be done: string myRequest = "abc=1&pqr=2&lmn=3"; string myResponse=""; string myUrl = "Where you want to post data"; System.IO.StreamWriter myWriter = null;// it will open a http connection with provided url System.Net.HttpWebRequest objRequest = (System.Net

Is there an enum for the ContentType property on a HttpWebResponse (“text/plain”, “application/octet-stream” etc.)?

不羁的心 提交于 2019-12-04 09:50:23
问题 The closest thing I could find was System.Net.Mime.MediaTypeNames but that doesn't seem to have everything (like json) since it seems to be more focused around email attachments. 回答1: An enum doesn't make much sense. MIME types are open-ended. That is, the list is not finite: new types are added from time to time. See RFC4288: Media Type Specifications and Registration Procedures 回答2: IANA's database is most likely to be complete, but you would need to parse those pages to get a flat list.

VB.NET Use WebRequest to check if URI is valid

為{幸葍}努か 提交于 2019-12-04 09:48:24
Looking for the best way to determine if a URI exists in VB.NET without downloading the actual content. System.IO.FileExists / My.Computer.FileSystem.FileExists can be used locally to determine if a file exists, is there an equivalent for the Web? Currently I am using a HttpWebRequest to check URI existance using the ResponseStream . This populates the stream if the target does exist and throws an exception if it doesn't. The function is being expanded to also check for PDF files (typically 5MB +), images, etc and it will be a waste of time/bandwidth to actually populate the content into a

Trying to get authentication cookie(s) using HttpWebRequest

血红的双手。 提交于 2019-12-04 09:44:30
问题 I have to scrape a table from a secure site and I'm having trouble logging in to the page and retrieving the authentication token and any other associated cookies. Am I doing something wrong here? public NameValueCollection LoginToDatrose() { var loginUriBuilder = new UriBuilder(); loginUriBuilder.Host = DatroseHostName; loginUriBuilder.Path = BuildURIPath(DatroseBasePath, LOGIN_PAGE); loginUriBuilder.Scheme = "https"; var boundary = Guid.NewGuid().ToString(); var postData = new

What uri pattern do I need to communicate with my PC from my handheld device?

怎甘沉沦 提交于 2019-12-04 06:19:32
问题 As I was reminded here, I need to probably use "ppp_peer" to programmatically connect from my Compact Framework app to my Web API app running on my PC. I have tried this (replacing an IPAddress with "ppp_peer"): string uri = string.Format("http://ppp_peer:28642/api/FileTransfer/GetHHSetupUpdate?serialNum={0}&clientVersion={1}", serNum, clientVer); ...but I get, " NullReferenceException " in "Main" (prior to this I got "Unable to Connect to the Remote Server"). I have a breakpoint in the

Writing cookies from CookieContainer to the IE cookie store

我与影子孤独终老i 提交于 2019-12-03 08:54:49
I want to navigate to a page in a web app from a desktop app. "No problem", I hear you say, "just fire up the default browser with the correct URL". However, the web app uses ASP.NET Forms Authentication, and the users don't want to see the login page because they have already authenticated with the same credentials in the desktop app. That sounds simple enough, all I have to do is emit an HTTP POST from the desktop app with that fakes the postback from the web app's login page. The web app will then set its authentication ticket and session state cookies, return them to me, and I will store

HttpWebResponse with MJPEG and multipart/x-mixed-replace; boundary=--myboundary response content type from security camera not working

≯℡__Kan透↙ 提交于 2019-12-03 07:10:37
I have an ASP.NET application that I need to show a video feed from a security camera. The video feed has a content type of 'multipart/x-mixed-replace; boundary=--myboundary' with the image data between the boundaries. I need assistance with passing that stream of data through to my page so that the client side plugin I have can consume the stream just as it would if I browsed to the camera's web interface directly. The following code does not work: //Get response data byte[] data = HtmlParser.GetByteArrayFromStream(response.GetResponseStream()); if (data != null) { HttpContext.Current

C# Xml in Http Post Request Message Body

心已入冬 提交于 2019-12-03 03:23:18
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 Gratzy 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.GetBytes(postData); req.ContentLength = bytes.Length; using (Stream os = req.GetRequestStream()) { os

C# How to set HttpClient Keep-Alive to false

两盒软妹~` 提交于 2019-12-02 22:17:26
I had a low performance problem with HTTP requests on .NET. The HTTP GET request to a REST API on the localhost took about 500 ms to complete. I spent a lot of time to fix it. I have tried many ways: HttpClient , HttpWebRequest , WebClient and RestSharp . None of them work. Most solutions on the Internet said to set Proxy parameter to null but it still won't work faster. The only way I found to reduce this time is to set the Keep-Alive parameter of request to false: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.KeepAlive = false;

Why am I getting, “Unable to connect to the remote server”?

梦想与她 提交于 2019-12-02 10:09:44
This err msg is the next one I get after resolving “NotSupportedException” as noted here I don't even reach the break point in the server code (set on the first line of the method that should be getting called). This is the relevant server code: [Route("api/PlatypusItems/PostArgsAndXMLFileAsStr")] public async void PostArgsAndXMLFileAsStr([FromBody] string stringifiedXML, string serialNum, string siteNum) { string beginningInvoiceNum = string.Empty; // <= Breakpoint on this line string endingInvoiceNum = string.Empty; XDocument doc = XDocument.Load(await Request.Content.ReadAsStreamAsync()); .