1.StreamToMemoryStream
MemoryStream StreamToMemoryStream(Stream instream) { MemoryStream outstream = new MemoryStream(); const int bufferLen = 4096 ; byte [] buffer = new byte [bufferLen]; int count = 0 ; while ((count = instream.Read(buffer, 0 , bufferLen))> 0 ) { outstream.Write(buffer, 0 , count); } return outstream; }
2.Stream.Length error: this stream does not support search
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + (data == "" ? "" : " ? " + Data)); request.Method = " GET " ; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { Stream rs = response.GetResponseStream(); var ms = StreamToMemoryStream (rs); ms.Seek( 0 , SeekOrigin.Begin); int buffsize =( int ) ms.Length ; //rs.Length This stream does not support searching, first convert to MemoryStream byte [] bytes = new byte [buffsize]; ms.Read(bytes, 0 , buffsize); ms.Flush();ms.Close(); rs.Flush();rs.Close(); }
Read More:
- [Solved] Stream Error: stream has already been operated upon or closed
- [Solved] iperf Analyze Error: unable to create a new stream: Invalid argument
- XML read process error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Content not allowed in preamble
- DB2 detects a syntax error in the DRDA data stream: 0x3 ERRORCODE= -4499, SQLSTATE=58009
- Git push error: error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
- [Solved] Git error: inflate: data stream error (invalid block type) error: corrupt loose object
- [Solved] Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
- [Nginx] Configure nginx to support websocket to solve the problem of returning 400 error
- How to Solve Error inflating class android.support.design.widget.FloatingActionButton
- [Solved] dhl: Error: LINQ to Entities does not support the specified type member “Date”
- [Solved] Android DataBinding Error: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 fragment Changes to Fragm
- [Solved] The version of springcloud must support the current version of springboot, otherwise the startup project will report an error: error starting ApplicationContext
- [Solved] swiper Error: The requested module ‘react’ is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export
- Cmake Setting Support C++11 This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options
- Vue error in render: “typeerror: cannot read property ‘length’ of undefined”
- Adjusted frame length exceeds 4096: 5637-discarded server solution
- [Solved] Doris StreamLoad Error: load by MERGE or DELETE need to upgrade table to support batch delete
- How to Solve Error: Heartbeating to master:7182 failed.
- [Solved] docker failed to solve: failed to solve with frontend dockerfile.v0: failed to create LLB definition
- [Solved] error: package android.support.design.widget does not exist