我正在尝试使用byte流从网址获取图像.但我收到此错误消息:
此流不支持搜索操作.
这是我的代码:
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
int i;
using (BinaryReader br = new BinaryReader(stream))
{
i = (int)(stream.Length);
b = br.ReadBytes(i); // (500000);
}
myResp.Close();
return b;
Run Code Online (Sandbox Code Playgroud)
我做错了什么人?
我正在获取结果streamreader对象.
我想将结果转换为byte [].
如何将streamreader转换为byte []?
谢谢
我正在尝试“屏幕抓取”一些数据我有一个请求如下(来自提琴手)
POST http://fallenlondon.storynexus.com/Auth/EmailLogin HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Referer: http://fallenlondon.storynexus.com/signup
User-Agent: Mine
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Cache-Control: max-age=0
l:
Origin: http://fallenlondon.storynexus.com/
DNT: 1
Accept-Encoding: utf-8
Accept-Language: en-GB,en;q=0.8
Cookie: ASP.NET_SessionId=05xq3gndu4nczvy5wsah5qyw; __utma=100212060.1740063036.1431282067.1431282067.1431284767.2; __utmb=100212060.14.10.1431284767; __utmc=100212060; __utmz=100212060.1431282067.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host: fallenlondon.storynexus.com
Content-Length: 54
Run Code Online (Sandbox Code Playgroud)
(内容是我的凭据) - 此标头与我在浏览器中手动查看网页所跟踪的请求相匹配。
我使用 HttpWebRequest.GetResponse() 发送这个我得到了回复
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: text/html; charset=utf-8
Date: Mon, 11 May 2015 20:54:15 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 4.0
X-Powered-By: ASP.NET
X-Server: Web1
Content-Length: 16900
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
这(再次)匹配我使用浏览器获得的内容。使用 fiddler,我可以看到 17k 的数据(html),我尝试使用... …