Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
==========================================================
GET http://birch:1001/ HTTP/1.1
User-Agent: Fiddler
Host: birch:1001
GET http://birch:1001/speakers HTTP/1.1
User-Agent: Fiddler
Host: birch:1001
<tmds:DataSource>
<tmds:HttpRequest url="/desktop/{dataset}/documents/quote/{id}">
</tmds:HttpRequest>
</tmds:DataSource>
[Fact]
public void HttpMessageContent_from_a_file()
{
var stream =
this.GetType().Assembly.GetManifestResourceStream("ClientSamples.StaticContent.HttpResponseMessage.txt");
var content = new StreamContent(stream);
var contentType = new MediaTypeHeaderValue("application/http");
contentType.Parameters.Add(new NameValueHeaderValue("msgtype", "response"));
@darrelmiller
darrelmiller / gist:8317564
Created January 8, 2014 14:28
Demo reading partial content with HttpClient
private static void TestBigDownload(string host)
{
var httpclient = new HttpClient() { BaseAddress = new Uri(host) };
var stream = httpclient.GetStreamAsync("pullbigresource").Result;
var bytes = new byte[10000];
var bytesread = stream.Read(bytes, 0, 1000);
@darrelmiller
darrelmiller / gist:8318796
Created January 8, 2014 15:45
Wininet seems to ignore no-cache request header.
private static async Task TestNoCache(string host)
{
var clientHandler = new WebRequestHandler();
clientHandler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default);
var client = new HttpClient(clientHandler) { BaseAddress = new Uri(host) };
var response = await client.GetAsync("/CacheableResource");
var request = new HttpRequestMessage()
{
Server Software: Microsoft-HTTPAPI/2.0
Server Hostname: OAK
Server Port: 1001
Document Path: /CacheableResource
Document Length: 22 bytes
Concurrency Level: 1000
Time taken for tests: 4.499 seconds
Complete requests: 60000
GET http://finance.services.appex.bing.com/Market.svc/AppTileV2?symbols=127.10.0000&contentType=0&tileType=0&locale=en-ca&symbolTypes= HTTP/1.1
User-Agent: Microsoft-WNS/6.3
Host: finance.services.appex.bing.com
Pragma: no-cache
=>
HTTP/1.1 200 OK
Content-Length: 1126
Content-Type: application/xml; charset=utf-8
Last-Modified: Fri, 10 Jan 2014 21:51:25 GMT
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Salesforce.Common.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Salesforce.Common
@darrelmiller
darrelmiller / gist:8548166
Created January 21, 2014 20:54
How to tell Web API 2.1 to allow errors to propagate up the MessageHandler pipeline so all exceptions can be converted to HttpResponseMessages in one place.
class Program
{
static void Main(string[] args)
{
var server = WebApp.Start("http://localhost:1002/", (app) =>
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Services.Replace(typeof(IExceptionHandler), new RethrowExceptionHandler());
class Program
{
static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 2;
var tasks = new Task[10];
for (int i = 0; i < 10; i++)
{
tasks[i] = Run();