客户端:
class Program
{
static void Main(string[] args)
{
DoIt();
}
private static void DoIt()
{
try
{
String serverUrl = "http://192.168.5.110:9090/Sum";
System.Console.WriteLine("Please enter the first number:");
String firstNumber = System.Console.ReadLine();
System.Console.WriteLine("The second number:");
String secondNumber = System.Console.ReadLine();
System.Console.WriteLine("Enter the web api URL, or empty as default:" + serverUrl);
String newServerUrl = System.Console.ReadLine();
if (!String.IsNullOrEmpty(newServerUrl))
{
serverUrl = newServerUrl;
}
String responseData = HttpClientHelper.PostResponse(serverUrl, new { first = firstNumber, second = secondNumber });
BeetleX.FastHttpApi.JsonResult responseResult = JsonConvert.DeserializeObject(responseData);
System.Console.WriteLine("Result:" + responseResult.Data);
}
catch (Exception ex)
{
System.Console.WriteLine(ex.StackTrace);
System.Console.WriteLine(ex.Message);
}
finally
{
System.Console.WriteLine("Continue?(Y/N):");
String c = System.Console.ReadLine();
if ("Y".Equals(c) || "y".Equals(c))
{
DoIt();
}
}
}
}
api服务端:
class Program
{
private static BeetleX.FastHttpApi.HttpApiServer mApiServer;
static void Main(string[] args)
{
mApiServer = new BeetleX.FastHttpApi.HttpApiServer();
mApiServer.Options.LogLevel = BeetleX.EventArgs.LogType.Debug;
mApiServer.Options.LogToConsole = true;
mApiServer.Debug();
mApiServer.Register(typeof(Program).Assembly);
mApiServer.Open();
Console.Write(mApiServer.BaseServer);
Console.Read();
}
}
[Controller]
public class Calculate : IController
{
[Post]
[JsonDataConvert]
public int Sum(int first, int second, IHttpContext context)
{
Console.WriteLine(context.Data);
return first+second;
}
[Post]
[JsonDataConvert]
public object SumObject(int first, int second, IHttpContext context)
{
Console.WriteLine(context.Data);
return first + second;
}
[NotAction]
public void Init(BeetleX.FastHttpApi.HttpApiServer server, string path)
{
}
}
下载链接:https://download.csdn.net/download/jasonhongcn/11619767
交流QQ群:676208164
网友评论