Runscope is now part of BlazeMeter.
Please find up-to-date documentation at guide.blazemeter.com.
Please find up-to-date API documentation at api.blazemeter.com.

C#: Debugging and Testing APIs and Backend Services with Runscope

The Runscope Traffic Inspector lets you see all of the API requests and responses you're sending and receiving from your code. To capture the requests, create a Gateway URL for the API you're calling. Below are some examples for using the Gateway URL with your favorite HTTP client.


HttpClient with RunscopeMessageHandler (Recommended) Library Docs

RunscopeMessageHandler automatically creates Gateway URLs for all requests made through the HttpClient instance with the handler registered.

using System.Net.Http;
using Runscope.Contrib;

var runscopeHandler = new RunscopeMessageHandler("bucket_key", new HttpClientHandler());
var client = new HttpClient(runscopeHandler);

var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("Name", "Grace Hopper"));
postData.Add(new KeyValuePair<string, string>("ID ", 12345));

var formContent = new FormUrlEncodedContent(postData);

var response = await client.PostAsync("https://yourapihere.com", formContent);
var content = await response.Content.ReadAsStringAsync();

HttpClient POST Request Example Library Docs

using System.Net.Http;

var client = new HttpClient();

var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("Name", "Grace Hopper"));
postData.Add(new KeyValuePair<string, string>("ID ", 12345));

var formContent = new FormUrlEncodedContent(postData);

var response = await client.PostAsync("https://yourapihere.com", formContent);
var content = await response.Content.ReadAsStringAsync();

RestSharp POST Request Example Library Docs

using RestSharp;

var client = new RestClient("https://yourapihere.com");

var request = new RestRequest("people", Method.POST);
request.AddParameter("name", "Grace Hopper"); 

// execute the request
var response = client.Execute(request);
var content = response.Content; // raw content as string

HttpWebRequest POST Request Example Library Docs

using System.Net;

string url = "https://yourapihere.com";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";

string data = "name=Grace%20Hopper"; // make sure this is URL encoded
request.ContentType = "application/x-www-form-urlencoded";

using (Stream requestStream = request.GetRequestStream())  
using (StreamWriter writer = new StreamWriter(requestStream, Encoding.ASCII))
{
    writer.Write(data);
}

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// careful, non-2xx responses will throw an exception
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream)) { 
    return reader.ReadToEnd(); 
}

Need help? We have you covered.

View the docs or contact our support team and we'll get back to you as soon as we're able to respond.