You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ag9 (JIRA)" <ji...@apache.org> on 2011/05/06 11:03:03 UTC

[jira] [Updated] (THRIFT-1162) THttpClient - provide ReadByte() method for server response

     [ https://issues.apache.org/jira/browse/THRIFT-1162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ag9 updated THRIFT-1162:
------------------------

    Attachment: THttpClient.cs

The attached file THttpClient.cs contains method *ReadByte()*. For getting data it method uses similar native method of *Stream* object *ReadByte()*. 
Original copy of THttpClient.cs was take from [THRIFT-1159|https://issues.apache.org/jira/browse/THRIFT-1159]
(it's not clear copy from svn) and has been changed according to issue cases (added method).

> 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
>              Labels: thrift
>         Attachments: THttpClient.cs
>
>   Original Estimate: 4m
>  Remaining Estimate: 4m
>
> 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