• 大小: 54KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-05
  • 语言: C#
  • 标签: C#  Winform  远程调用  

资源简介

C#编写的Winform程序,可以丢在服务器定时调用接口,无需配置,比Win服务方便一点,源码开放可自行拓展

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CallInter
{
    public partial class Form1 : Form
    {
        int count = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            count = count + 1;
            label3.Text = “最新执行时间:“ + DateTime.Now + “ 总共执行了“ + count + “次“;
            GetPost(this.textBox1.Text this.textBox2.Text);
        }

        private void button1_Click(object sender EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.textBox1.Text))
            {
                MessageBox.Show(“执行前必须输入接口地址与参数“);
                return;
            }
            label3.Text = “服务已启动...“;
            saveCf(“reurl“ this.textBox1.Text);
            if (!string.IsNullOrWhiteSpace(textBox2.Text))
            {
                saveCf(“repar“ this.textBox2.Text);
            }

            if (!string.IsNullOrWhiteSpace(textBox3.Text)) 
            {
                saveCf(“loaddate“ textBox3.Text);
            }
            timer1.Interval = Convert.ToInt32(textBox3.Text) * 1000;
            this.button1.Enabled = true;
            this.timer1.Enabled = true;
        }

        private void button2_Click(object sender EventArgs e)
        {
            this.timer1.Enabled = false;
            this.button1.Enabled = true;
            this.button2.Enabled = false;
        }

        public string GetPost(string url string par string token = ““)
        {
            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                var data = Encoding.ASCII.GetBytes(par);
                request.Method = “POST“;
                request.ContentType = “application/x-www-form-urlencoded“;
                request.ContentLength = data.Length;
                if (!string.IsNullOrWhiteSpace(token))
                    request.Headers.Add(“ApiAuthorization“ token);

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data 0 data.Length);
                }

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

                return new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch
            {
                return ““;
            }
        }

        /// 
        /// 获取配置文件中的路径
        /// 

        /// 
        public static string GetFileUrl(string fileurl)
        {
            if (!string.IsNullOrWhiteSpace(fileurl))
            {
                return System.Configuration.Configuration

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-05 16:07  CallInter\
     文件         917  2019-03-05 16:04  CallInter.sln
     文件         288  2019-03-16 11:16  CallInter\App.config
     目录           0  2019-03-05 16:04  CallInter\bin\
     目录           0  2019-08-23 15:35  CallInter\bin\Debug\
     文件       12800  2019-08-23 17:24  CallInter\bin\Debug\CallInter.exe
     文件         346  2019-09-12 14:32  CallInter\bin\Debug\CallInter.exe.Config
     文件       28160  2019-08-23 17:24  CallInter\bin\Debug\CallInter.pdb
     文件       22984  2019-08-23 17:24  CallInter\bin\Debug\CallInter.vshost.exe
     文件         347  2019-09-12 14:32  CallInter\bin\Debug\CallInter.vshost.exe.Config
     文件         490  2012-06-06 02:06  CallInter\bin\Debug\CallInter.vshost.exe.manifest
     文件        3847  2019-03-16 11:56  CallInter\CallInter.csproj
     文件        4480  2019-08-23 17:24  CallInter\Form1.cs
     文件        6654  2019-08-23 17:24  CallInter\Form1.Designer.cs
     文件        6011  2019-08-23 17:24  CallInter\Form1.resx
     目录           0  2019-03-05 16:04  CallInter\obj\
     目录           0  2019-08-23 17:24  CallInter\obj\Debug\
     文件        1443  2019-08-23 17:24  CallInter\obj\Debug\CallInter.csproj.FileListAbsolute.txt
     文件         975  2019-08-23 17:24  CallInter\obj\Debug\CallInter.csproj.GenerateResource.Cache
     文件        2364  2019-08-23 17:18  CallInter\obj\Debug\CallInter.csprojResolveAssemblyReference.cache
     文件       12800  2019-08-23 17:24  CallInter\obj\Debug\CallInter.exe
     文件         180  2019-08-23 17:24  CallInter\obj\Debug\CallInter.Form1.resources
     文件       28160  2019-08-23 17:24  CallInter\obj\Debug\CallInter.pdb
     文件         180  2019-08-23 15:25  CallInter\obj\Debug\CallInter.Properties.Resources.resources
     文件        1308  2019-03-16 11:07  CallInter\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7088  2019-08-23 15:07  CallInter\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2019-03-05 16:04  CallInter\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2019-03-05 16:04  CallInter\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2019-03-05 16:04  CallInter\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2019-03-05 16:04  CallInter\obj\Debug\TempPE\
     文件         521  2019-03-05 16:04  CallInter\Program.cs
............此处省略6个文件信息

评论

共有 条评论