2019年第一篇博客,本人菜鸟,有路过的大神如果有更好的实现方法,请多多指教!
最近搞的一个项目,由于特殊原因,需要由winform的程序调用java写的接口来实现业务的需求。在此之前参考过很多网上的例子,觉得以下这种方式最适合不过了。废话不多说,直接上代码!
说明:需要使用插件:Newtonsoft.Json
-
自己写的封装类:WebServiceHelper
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using DAL;
using System.Xml;
namespace DL_MaterialCabinetScanning
{
public class WebServiceHelper
{
public delegate void HttpHandler(string responseStr);
public event HttpHandler HttpResponsed;
/// <summary>
/// 调用api返回json
/// </summary>
/// <param name="methodParam">方法名</param>
/// <param name="jsonParamstr">接收参数</param>
/// <returns></returns>
public void HttpPost(string methodParam, string jsonParamstr)
{