1
2
3
4
5
let f (arr: string array) =
  let r= Array.map Encoding.ASCII.GetBytes arr |> Array.map Int64.of_int |> Array.sum


  request.ContentLength <- r

P.S. For case your API has some version of the writev() family functions why not use it instead?

By on 7/31/2009 12:49 PM ()

Well, this didn't work, had an error with getbytes.

I think I need to try a different approach though to send a complex data type. Its a .net solution both the web service and the consumer.

By on 7/31/2009 6:53 PM ()
1
2
3
4
5
6
7
8
9
10
open System.Net
open System.Text

let f (request: FileWebRequest) (arr: string array) =
  let aux (s: string) = Encoding.ASCII.GetBytes s
  let r = Array.map (aux >> Array.length >> int64) arr |> Array.sum
  request.ContentLength <- r
  use strm = request.GetRequestStream ()
  for s in arr do
    Array.iter strm.WriteByte (aux s)
By on 8/1/2009 2:16 AM ()

I couldn't figure how to adapt it this for my purposes.

Instead using a modification provided by Robert P. I have instead one long string being posted.

/// Returns response of HTTP post
let HttpPost (url:string) (itemsToPost: list<string>) =
let postData = List.fold (+) "" itemsToPost
let request = WebRequest.Create(url) in
request.Method <- WebRequestMethods.Http.Post;
request.ContentType <- "application/x-www-form-urlencoded";

let bytes = Encoding.ASCII.GetBytes(postData) in
request.ContentLength <- Int64.of_int bytes.Length;

try
let stream = request.GetRequestStream() in
stream.Write(bytes,0,bytes.Length);
stream.Close();

let response = request.GetResponse( ) in
let reader = new StreamReader( response.GetResponseStream() ) in
reader.ReadToEnd()
with
| :? ArgumentException -> "false";
| :? System.Exception as e -> "false";

By on 8/3/2009 9:02 AM ()

Thanks. ssp.

I'll give this a try and post in a couple days how this worked out.

By on 8/2/2009 10:57 AM ()

I'm not familiar with writev. I want to send an array of strings to a .NET web service with one method call.

By on 7/31/2009 1:04 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper