Use HTTP Within Its Transport Boundaries

Select Sharp Runtime HTTP components and avoid assuming TLS or browser networking parity.

AdvancedTutorial

Choose targets

set(SHARP_RUNTIME_COMPONENTS
    Net.Http
    Net.Http.Headers
)
target_link_libraries(app PRIVATE
    SharpRuntime::Net.Http
    SharpRuntime::Net.Http.Headers
)

Make a synchronous plain-HTTP request

#include <iostream>

#include "System/Net/Http/HttpClient.hpp"

using System::Net::Http::HttpClient;

int main()
{
    HttpClient client;
    client.setDefaultHeader("Accept", "text/plain");

    auto response = client.Get("http://example.com/");
    response->EnsureSuccessStatusCode();

    auto content = response->getContentProperty();
    if (!content) return 1;
    std::cout << content->ReadAsString() << '\n';
    return 0;
}
Compile-verified, intentionally not run

This exact shape compiles and links against the pinned source. The audit made no external network request and claims no endpoint result.

Transport boundary

Document and test against plain http:// behavior. Sharp Runtime does not currently provide TLS, certificates, SslStream or HTTPS. WebSockets similarly support ws://, not wss://.

Error handling

  • Distinguish DNS resolution, connect and protocol failures; the current API has no general request cancellation-token/timeout overload.
  • Validate headers; names are currently case-sensitive and default/request fields can duplicate semantically.
  • Responses are fully buffered and have no current hard size limit; avoid untrusted or large endpoints.
  • No automatic redirect following is provided.
  • Prefer the synchronous public pattern: async helpers capture the HttpClient owner, which must outlive completion.
  • Treat environment network restrictions as a distinct diagnostic category.
Security

Do not send credentials or sensitive data over the plain HTTP/WebSocket transport offered by the current runtime. Use a separately audited secure transport layer if the application requires it.