NetBurner 3.5.6
PDF Version
WebClient Http Request Methods

HTTP Methods Test Application

Overview

This repository contains two complementary networking applications designed for testing and development purposes:

  1. HTTP Methods Test Client (main.cpp) - A NetBurner embedded C++ application that tests various HTTP methods against a test server
  2. HTTP Echo Server (main.go) - A Go-based HTTP server that echoes back request details in both HTML and JSON formats

HTTP Methods Test Client (main.cpp)

Description

The HTTP Methods Test Client is a NetBurner embedded application written in C++ that systematically tests different HTTP methods against a configurable endpoint. The application demonstrates proper usage of NetBurner's HTTP client libraries and JSON handling capabilities.

Features

  • Multiple HTTP Method Testing: Tests POST, PUT, GET, HEAD, and DELETE methods
  • JSON Request/Response Handling: Sends structured JSON data and parses responses
  • HTML Content Retrieval: Can request and display HTML responses
  • Device Information: Includes MAC address and uptime in requests
  • Automated Testing Loop: Continuously cycles through different HTTP methods
  • Network Diagnostics: Optional HTTP debugging output
  • Configurable Target: Easy to change target URL for different test servers

HTTP Methods Tested

  1. POST - Sends JSON message with device info and timestamp
  2. PUT - Sends JSON message with device info and timestamp
  3. GET - Requests HTML echo response
  4. HEAD - Requests headers-only response
  5. DELETE - Sends DELETE request for testing

Configuration

  • Target URL: Currently set to http://10.2.0.63:20035/
  • Request Headers: Configurable Accept headers (application/json or text/html)
  • Timeout: 10 seconds per request
  • Test Interval: 2 seconds between each method test

JSON Request Format

The application sends JSON requests with the following structure:

{
"DEVICEID": "XX:XX:XX:XX:XX:XX",
"UPTIME": 12345,
"MESSAGE": "At the tone the time will be: 12345"
}

Dependencies

Usage

  1. Configure the target URL in the source code
  2. Build and deploy to NetBurner hardware
  3. Ensure network connectivity
  4. Application will automatically start testing HTTP methods
  5. Monitor output via serial console or system diagnostics

HTTP Echo Server (main.go)

Description

The HTTP Echo Server is a Go-based web server designed to echo back HTTP request details. It serves as a perfect companion for testing HTTP clients by providing detailed information about received requests in both human-readable HTML and machine-readable JSON formats.

Features

  • Content Negotiation: Returns HTML or JSON based on Accept headers
  • Complete Request Echo: Displays method, resource, headers, body, and raw request
  • Template-Based Responses: Uses Go templates for flexible output formatting
  • Configurable Port: Uses SERVER_PORT environment variable or default port 20035
  • Error Handling: Proper HTTP error responses for template or processing errors

Response Formats

HTML Response

Provides a formatted web page showing:

  • HTTP Method used
  • Resource/URI requested
  • All request headers with values
  • Request body content
  • Complete raw HTTP request dump

JSON Response

Returns structured JSON with:

  • Method string
  • Resource/URI string
  • Headers object with arrays for multi-value headers
  • Body content as string
  • Complete raw request as string

Configuration

  • Default Port: 20035
  • Environment Variable: SERVER_PORT overrides default port
  • Content Type Detection: Automatically detects JSON requests via Accept header

Running the Server

# Use default port 20035
go run main.go
# Use custom port via environment variable
SERVER_PORT=8080 go run main.go

Template System

The server uses Go's template system with custom functions:

  • set: Sets a counter value
  • incr: Increments a counter value

This allows for complex template logic and formatting of response data.

Integration Testing

These two applications work together to provide a complete HTTP testing environment:

  1. Start the Go echo server on the target network
  2. Configure the NetBurner client with the server's IP address and port
  3. Deploy and run the client - it will automatically begin testing
  4. Monitor responses via the client's serial output and server logs

Network Requirements

  • Both applications should be on the same network or have routing between them
  • Default port 20035 should be available (or configure alternative)
  • NetBurner device needs DHCP or static IP configuration
  • Firewall rules should allow HTTP traffic between client and server

Development Notes

NetBurner Client Development

  • Uses NetBurner's RTOS and networking stack
  • Requires proper initialization and network waiting
  • JSON handling through NetBurner's ParsedJsonDataSet class
  • HTTP operations through DoJsonHttp and DoHttpEx functions

Go Server Development

  • Standard Go HTTP server with template system
  • Cross-platform compatibility
  • Minimal dependencies (standard library only)
  • Easy to extend with additional endpoints or features

Troubleshooting

Common Issues

  1. Network Connectivity: Ensure both devices can reach each other
  2. Port Conflicts: Check if port 20035 is available or configure alternative
  3. Timeout Issues: Adjust timeout values if network is slow
  4. JSON Parsing Errors: Verify JSON format compatibility
  5. Template Errors: Check server logs for template parsing issues

Debug Features

  • NetBurner client: Enable SetHttpDiag(true) for verbose HTTP debugging
  • Go server: Built-in request logging to console
  • System diagnostics available on NetBurner platform