Welcome
Si Carrington is a web developer in the UK, with a passion for technology. Si loves writing code, developing software, learning new languages and enhancing things.
Si develops primarily using C#, ASP.net, SQL Server, Javascript. This site is has morphed through various of Si's little projects, and is currently
hosting his occasional blog, alongside a couple of other things he has developed, such as his
Flickr photostream with colour histogram searching, and
a few bits of silverlight, Javascript and web services here and there. This site was built by Si Carrington,
handcrafted into a growing number of libraries and tools.
Enjoy, and feel free to contact Si Carrington, or find me on twitter, Facebook, LinkedIn..
The Blog 
HTML5, CSS3, SVG support finally on their way along with standards compliancy (again?!), a new javascript engine, and moving rendering to the GPU. But there is probably still a while to wait. Still, these early murmerings are positive signs!
The once every two years release cycle for IE means a continuing wait for long-awaited features. But a platform preview is available here for those who want to see what the IE9 team is working towards. Have you tested your site yet?
Posted By: Si Carrington |
17 March 2010 |
Comments (0)
|
Trackbacks (0)
Share:
Is google wave dead? Does anyone know? The recent seemingly hurried launch of Buzz has put google in some hot water as a result of the close integration of the tool with gmail and some slightly lack/not well understood/not well advertised privacy concerns. Basically, by default when Buzz launched, if you responded positively to the advertisement you were prompted with when you checking your gmail, all your existing contacts could start to see all your buzzing. Google has made several tweaks to the service since launch to try to address some such concerns.
Whilst checkin out Buzz, there have been many things that seem reminiscent of google wave. Particularly, the idea of public "waves" or conversation threads. Google wave was, well it still is, an invitation-only beta that required you to use a completely different email account than your gmail account. Although there was some integration in that your gmail contacts who joined wave would appear in your wave contacts/follow list.
I personally have pretty much stopped using wave becausethere weren't too many of my contacts on it, and the novelty wore off. Also, the performance is poor (depending on your javascript engine). But it seems to me that gmail integration of wave like features is a much more effective way of getting users - and buzz has quickly gained a large number of users thanks to the gmail integration. How many people would have been prepared to switch from gmail to wave?
Google has admitted mistakes in the launch of buzz - but there lackluster response to facebook and twitter does seem odd. Why was buzz rushed out the door at this point in time?
Posted By: Si Carrington |
24 February 2010 |
Comments (0)
|
Trackbacks (0)
Share:
I've recently been refreshing my memory on some basic HTTP post functionality in relation to a project I have been working on. Specifically, I have needed to interface with a simple restful web service via HTTP posts.
The advantage of this kind of interface is its simplicity over something such as SOAP web services, the face that it is platform agnostic and also requires less bandwidth than SOAP (although in this instance the bandwidth isn't a huge concern).
However, this specific scenario called for files to be uploaded into HTTP posts, which I had to create programmatically. Now, your standard HTTP post can very simply be constructed in a very similar way to a get request.
1: public HttpWebResponse simpleHTMLPost(string remoteURI, NameValueCollection nvc)
2: {
3: StringBuilder sb = new StringBuilder();
4: sb.Append("?");
5: foreach (string key in nvc.Keys)
6: {
7: sb.Append(string.Format("{0}={1}&", key, nvc[key]));
8: }
9:
10: string postData = sb.ToString();
11:
12: byte[] buffer = System.Text.Encoding.UTF8.GetBytes(postData);
13: HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(remoteURI + postData);
14: myRequest.Method = "POST";
15:
16: // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
17: HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();
18: return myHttpWebResponse;
19: }
Generally, you can happily use a simple approach as above and let the .net internals deal with formatting the request appropriately. However, when you want to upload files with the request, things get a little more complicated. You need to upload the bytes of your file into your request, which means taking control of composition of all parameters in the request. Specifically, you need to get involved in the actual formatting of the post request itself, specifying content disposition, data field boundaries etc (cast your minds back to what an HTML post looks like - or use a basic HTML form and fiddler to generate your own!). Something like the following is what most of your post data items will look like:
------------------------------8cc6349d4ae3087
Content-Disposition: form-data; name="firstname";
simon
Once you have the basic code for this approach, however it is simple to reuse. For the case of any files you want to upload, you need to read the file bytes and insert these into your request stream. Set the content type of each file as you go. The code below is a rough example servicing a request which includes simple parameters along with files. (Note this would require further testing and error checking before production usage!) Hopefully it will serve as a useful guide - see the comments in the code for further details.
1: public HttpWebResponse fileHTMLPost(string remoteURI, NameValueCollection simpleNVC, NameValueCollection fileNVC)
2: {
3: long length = 0;
4: string boundary = "----------------------------" +
5: DateTime.Now.Ticks.ToString("x");
6:
7: //Create the HTTP request, specifying multipart form data
8: HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(remoteURI);
9: httpWebRequest2.ContentType = "multipart/form-data; boundary=" +
10: boundary;
11: httpWebRequest2.Method = "POST";
12: httpWebRequest2.KeepAlive = true;
13: httpWebRequest2.Credentials =
14: System.Net.CredentialCache.DefaultCredentials;
15:
16: Stream memStream = new System.IO.MemoryStream();
17:
18: //Formulate boundary which is used to mark parameter endings
19: byte[] boundarybytes = System.Text.Encoding.UTF8.GetBytes("\r\n--" +
20: boundary + "\r\n");
21:
22: //Form data template is used to provide template for format of
23: //simple post items
24: string formdataTemplate = "\r\n--" + boundary +
25: "\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
26:
27: //Output the simple keys to the request
28: foreach (string key in simpleNVC.Keys)
29: {
30: string formitem = string.Format(formdataTemplate, key, simpleNVC[key]);
31: byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
32: memStream.Write(formitembytes, 0, formitembytes.Length);
33: }
34: memStream.Write(boundarybytes, 0, boundarybytes.Length);
35:
36: //File template is used as a template for file items
37: string fileTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/pdf\r\n\r\n";
38: foreach (string key in fileNVC.Keys)
39: {
40: string header = string.Format(fileTemplate , key, Path.GetFileName(fileNVC[key]));
41:
42: byte[] filebytes = System.Text.Encoding.UTF8.GetBytes(header);
43: memStream.Write(filebytes, 0, filebytes.Length);
44: length += filebytes.Length;
45:
46: //Open the file for writing to the request stream.
47: //Note we are assuming the key-value contains the path to file
48: FileStream fileStream = new FileStream(fileNVC[key], FileMode.Open, FileAccess.Read);
49: byte[] buffer = new byte[1024];
50: int bytesRead = 0;
51:
52: //Write the fie bytes to the request
53: while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
54: {
55: memStream.Write(buffer, 0, bytesRead);
56: length += bytesRead;
57: }
58:
59: memStream.Write(boundarybytes, 0, boundarybytes.Length);
60: length += boundarybytes.Length;
61:
62: fileStream.Close();
63: }
64:
65: httpWebRequest2.ContentLength = memStream.Length;
66:
67: Stream requestStream = httpWebRequest2.GetRequestStream();
68:
69: memStream.Position = 0;
70: byte[] tempBuffer = new byte[memStream.Length];
71: memStream.Read(tempBuffer, 0, tempBuffer.Length);
72: memStream.Close();
73: requestStream.Write(tempBuffer, 0, tempBuffer.Length);
74: requestStream.Close();
75:
76: WebResponse webResponse2 = httpWebRequest2.GetResponse();
77: return (HttpWebResponse)webResponse2;
78: }
Posted By: Si Carrington |
18 February 2010 |
Comments (0)
|
Trackbacks (0)
Share:
View more blog postings