현재 내가 문제를 직면하고있어하지만 난 대답을 예상받지 못했습니다 .. 아래는 내 예제 코드입니다 : -마지막 행 공간 스트림 작성기를 제거하는 방법은 무엇입니까? , 내가 StreamWriter 클래스를 사용하여 텍스트 내용을 쓰기 위해 노력하고있어 파일을 만드는 동안
은내 C# 코드는 같다
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=20776,CODECS="avc1.66.41",RESOLUTION=320x240
chunk.m3u8?nimblesessionid=62
&token=42712adc-f932-43c7-b282-69cf349941da
하지만 내 예상 출력 : - -이 : -처럼 위의 코드의
public void ProcessRequest(HttpContext context)
{
// Create a connexion to the Remote Server to redirect all requests
RemoteServer server = new RemoteServer(context);
// Create a request with same data in navigator request
HttpWebRequest request = server.GetRequest();
// Send the request to the remote server and return the response
HttpWebResponse response = server.GetResponse(request);
context.Response.AddHeader("Content-Disposition", "attachment; filename=playlist.m3u8");
context.Response.ContentType = response.ContentType;
Stream receiveStream = response.GetResponseStream();
var buff = new byte[1024];
int bytes = 0;
string token = Guid.NewGuid().ToString();
while ((bytes = receiveStream.Read(buff, 0, 1024)) > 0)
{
//Write the stream directly to the client
context.Response.OutputStream.Write(buff, 0, bytes);
context.Response.Write("&token="+token);
}
//close streams
response.Close();
context.Response.End();
}
출력이 보이는
,#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=20776,CODECS="avc1.66.41",RESOLUTION=320x240
chunk.m3u8?nimblesessionid=62&token=42712adc-f932-43c7-b282-69cf349941da
난 그냥 대신 새로운 라인의 같은 라인에서 해당 토큰 PARAM ..
가 감사를 원했다.
서버에서받은 데이터가 이미 개행 문자로 끝나지 않았습니까? 그렇다면'context.Response'에 쓰기 전에 필터링해야합니다. – jcb
@jcb 데이터를 바이트 단위로 가져 오는 중입니다. 파일에 기록하기 전에 어떻게 필터링 할 수 있습니까? 예제 코드를 제공해 줄 수 있습니까? – IPS
당신은'if (buff [bytes-1] == 0x0a) bytes - = 1;'과 같은 일을 할 수 있는데, 이것은 개행 문자 (0x0a가 16 진수라면 '\ n')가 당신이받은 마지막 바이트, 그리고 마치 1 바이트 적게받은 것처럼 행동합니다. 그러나 서버에 따라 캐리지 리턴 바이트 ('\ r'또는 0x0d) 또는 메시지의 끝으로 둘 다 나타날 수 있습니다. 필요에 따라 적응 :) – jcb