THttpClient - provide ReadByte() method for server response
-----------------------------------------------------------
Key: THRIFT-1162
URL: https://issues.apache.org/jira/browse/THRIFT-1162
Project: Thrift
Issue Type: New Feature
Components: C# - Library
Environment: win2k, .net2
Reporter: ag9
Priority: Trivial
For now THttpClient supports just one way to read data from server response -
the method Read(byte[] buf, int off, int len). But at the moment of getting
data user don't know size of getting data so can't determine size of array
instance exactly (see sample below).
By example,
server code (simple asp.net app):
{code:java}
public class post : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (context.Request.UserAgent=="C#/THttpClient") {
context.Response.ContentType = "application/text";
context.Response.ContentEncoding =
System.Text.Encoding.Default;
context.Response.Write("thrift server response");
}
}
...
{code}
client code (console app):
{code:java}
Uri uri = new Uri("http://localhost:3968/TimeServerSample/post.ashx");
THttpClient transport = new THttpClient(uri);
transport.Proxy = WebRequest.DefaultWebProxy;
string postData = "test";
transport.Write(UTF8Encoding.UTF8.GetBytes(postData));
transport.Flush();
byte[] arr = new byte[1024];
transport.Read(arr, 0, 1024);
Console.WriteLine(System.Text.UTF8Encoding.UTF8.GetString(arr));
{code}
Would be better to define (in addition to Read) method *ReadByte* (like public
method in Stream class) for getting byte array byte for a byte. Something like
that:
{code:java}
System.Collections.ArrayList al = new System.Collections.ArrayList();
int res = 0;
while ( res != -1) {
res = transport.ReadByte();
if (res > -1) al.Add((byte)res);
}
byte[] bytes = (byte[])al.ToArray(typeof(byte));
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira