httpwebresponse

C# file export issue

半城伤御伤魂 提交于 2019-12-10 16:48:37
问题 I use this code to export/open files (pdf/xls/doc). Response.Clear(); Response.Buffer = true; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Charset = "UTF-8"; Response.ContentType = mimeType; Response.AppendHeader("content-disposition", "inline; filename=" + fileName + "." + extension); Response.BinaryWrite(bytes); Response.End(); When I open a doc file with Word and click export to xls or pdf, nothing happens until I close Word. After I close Word I am already able to open

VB.NET HttpWebRequest download file in chunks

主宰稳场 提交于 2019-12-10 12:17:27
问题 I'm looking for a help with following: In my Windows Forms application, I'm downloading the file located on remote server I control. My code below: Public Shared Function DownloadFileWithPOST(ByVal httpPath As String, ByVal storePath As String, postdata As String) As String Try Dim theResponse As HttpWebResponse Dim theRequest As HttpWebRequest Dim postdatabytes As Byte() theRequest = HttpWebRequest.Create(httpPath) If My.Settings.ProxyURL <> "" Then Dim prx As New WebProxy(My.Settings

Timeout with HttpWebResponse in .NET

走远了吗. 提交于 2019-12-10 11:50:36
问题 I have the following code, and after ~60 times calling it (20 concurrent connections) it starts timing out. if i lower the timeout from 10 minutes to 1 minute, they start timing out at ~34 downloads. what gives? i know that you can get this if you don't properly close your response, but i'm definitely closing it: //=============================================================================== /// <summary> /// Executes the request and returns the response as a byte array. Useful if the ///

Why is my HttpWebRequest POST method to my WebAPI server failing?

百般思念 提交于 2019-12-10 10:22:48
问题 I've successfully received data from my WebAPI project ("GET"), but my attempt to Post is not working. Here is the relevant server/WebAPI code: public Department Add(Department item) { if (item == null) { throw new ArgumentNullException("item"); } departments.Add(item); return item; } ...which fails on the "departments.Add(item);" line, when this code from the client is invoked: const string uri = "http://localhost:48614/api/departments"; var dept = new Department(); dept.Id = 8; dept

Should WebException.Response.GetResponseStream() be close / disposed?

别来无恙 提交于 2019-12-08 17:58:26
问题 When I catch a .NET WebException , should I close / dispose the Response.GetResponseStream() ? The MSDN example does not close or dispose anything in the exception. Many SO answers recommend disposing the response and / or the stream. I disposed the stream and this caused big problems. Because GetResponseStream() (always? / sometimes?) returns the same instance. So when I get the response stream and then dispose it, then maybe rethrow the exception to another layer that also gets the response

There is an error in XML document (1,2) , System.InvalidOperationException: <AuthorizationResult xlms:“”> was not expected

大兔子大兔子 提交于 2019-12-08 15:11:38
问题 XML sent from API <AuthenticationResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <PAPIErrorCode>0</PAPIErrorCode> <ErrorMessage/> <AccessToken>StringAccessToken</AccessToken> <AccessSecret>StringAccessToken</AccessSecret> <PolarisUserID>PolarisSampleUser</PolarisUserID> <BranchID>7</BranchID> <AuthExpDate>2013-05-27T16:57:46.323</AuthExpDate> </AuthenticationResult> Classes for Response using System; using System.Collections.Generic; using System.Linq; using System.Text; using

WebRequest follow redirect

筅森魡賤 提交于 2019-12-08 04:16:23
问题 I have a page (url a) which submits a form programmatically using a WebRequest. The page that accepts the form request does a bunch of stuff and then redirects to another page (url b) Is it possible at all to perform the webrequest (which reads, processes and redirects the form request), which then makes the current page (url a) redirect to the webrequest end location (url b). I currently have; HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(url + postVars); myRequest

Problems with PayPal API Http call

佐手、 提交于 2019-12-07 07:08:31
问题 I've integrated an option for users to pay via PayPal their online shopping on the web shop that I'm creating. The problem came up suddenly when I started to get this error: You must write ContentLength bytes to the request stream before calling [Begin]GetResponse. And the code for the Http call is as following: public string HttpCall(string NvpRequest) { string url = pEndPointURL; string strPost = NvpRequest + "&" + buildCredentialsNVPString(); strPost = strPost + "&BUTTONSOURCE=" +

Could not post on WebRequest if the Content Length > 7kb using C#

做~自己de王妃 提交于 2019-12-07 03:37:14
问题 I am trying to post a Json to our web service. My problem is that when my request.ContentLength exceeds 7kb. I will get a web exception 500 at request.GetResponse(). But if my request.ContentLength is below 7kb, my post is successfully sent. Error Message: The remote server returned an error: (500) Internal Server Error. Source code: public static string JsonPost(string url, string method, string postData) { Uri address = new Uri(url + method); HttpWebRequest request = WebRequest.Create

How to read the response stream before the Http response completes

故事扮演 提交于 2019-12-07 03:24:32
问题 When making a request using HttpWebRequest object, I need to call the method GetResponse() to send the request and get the response back. The problem with this method is that it doesn't return the response object until all data has been received. Say I am downloading a 100 MB file, I won't be able to read it until the response finish and all the 100 MB is downloaded. What I want is to be able to read the response stream bytes as soon as they arrive, without waiting for the response to