add request api

master
ZGGSONG 3 years ago
parent 58d2b56352
commit 4ce83087f3

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace S3Demo.Model
{
public class ReqData
{
public string ruleName { get; set; }
public int picReq { get; set; }
}
public class RespData
{
/// <summary>
/// 返回代码200 接口访问成功
/// </summary>
public int code { get; set; }
/// <summary>
/// 错误代码
/// </summary>
public int errorcode { get; set; }
/// <summary>
/// 是否有翻页?
/// </summary>
public bool hasPage { get; set; }
/// <summary>
/// 接口返回message
/// </summary>
public string message { get; set; }
public Result result { get; set; }
}
public class Result
{
/// <summary>
/// true 逻辑判断成功 code=200 && successful=true 接口调用成功
/// </summary>
public bool successful { get; set; }
/// <summary>
/// Ok/Info Detail
/// </summary>
public string message { get; set; }
/// <summary>
/// 小板条码
/// </summary>
public List<string> snDetails { get; set; }
/// <summary>
/// 绑定信息
/// </summary>
public string emappings { get; set; }
}
}

@ -0,0 +1,52 @@
using System.IO;
using System.Net;
using System.Text;
namespace S3Demo.Model
{
public class HttpModel
{
/// <summary>
/// POST请求
/// </summary>
/// <param name="url">请求地址</param>
/// <param name="postData">JSON格式请求数据</param>
/// <returns>返回响应内容</returns>
public static string PostUrl(string url, string postData)
{
string result = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.Timeout = 10000;
req.ContentType = "application/json";
byte[] data = Encoding.UTF8.GetBytes(postData);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
return result;
}
}
}

@ -4,16 +4,16 @@ using Amazon.S3;
using System;
using S3Demo.Storage;
using S3Demo.Model;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.IO;
using Ksat.Supplyment.Library.Model;
using Newtonsoft.Json;
namespace S3Demo
{
public class Run
{
//请求接口
private static string url = "http://127.0.0.1:9000/api/workflowcenter/anonymous/v1/trackgo/track";
private static BasicAWSCredentials credentials = new BasicAWSCredentials("admin", "admin123.");
//private static BasicAWSCredentials credentials = new BasicAWSCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
private static string bucketName = "minio/test";
@ -163,6 +163,7 @@ namespace S3Demo
string flag = ObjectModel.Putobjectswithtags(bucketName, S3Path, e.FullPath, tags, credentials, conf).Result;
if (flag.Equals("OK"))
{
//保存至数据库
using (var dev = new CodeFirstDbContext())
{
dev.UploadFinishs.Add(new Ksat.Supplyment.Library.Model.Uploader.UploadFinish()
@ -173,8 +174,13 @@ namespace S3Demo
RetryCount = 1,
RequestData = S3Path
});
string res = dev.SaveChanges() == 1 ? "上传并保存成功" : "上传成功,保存失败";
Console.WriteLine(res);
int saveInfo = dev.SaveChanges();//1: 保存至数据库成功,否则保存失败
ReqData req = new ReqData();
RespData resp = new RespData();
req.ruleName = "picSave";
req.picReq = saveInfo;
resp = JsonConvert.DeserializeObject<RespData>(HttpModel.PostUrl(url, JsonConvert.SerializeObject(req)));
Console.WriteLine("resp: " + resp.code + " " + resp.message);
}
}
Console.WriteLine("S3对象存储路径: " + bucketName + "/" + S3Path);

@ -50,6 +50,9 @@
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SQLite.CodeFirst, Version=1.7.0.34, Culture=neutral, PublicKeyToken=eb96ba0a78d831a7, processorArchitecture=MSIL">
<HintPath>..\packages\SQLite.CodeFirst.1.7.0.34\lib\net45\SQLite.CodeFirst.dll</HintPath>
</Reference>
@ -74,7 +77,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Model\BucketModel.cs" />
<Compile Include="Model\HttpModel.cs" />
<Compile Include="Model\ObjectModel.cs" />
<Compile Include="Model\Request.cs" />
<Compile Include="Storage\CreateBucket.cs" />
<Compile Include="Storage\ListObjects.cs" />
<Compile Include="Run.cs" />

@ -3,6 +3,7 @@
<package id="AWSSDK.Core" version="3.7.5.2" targetFramework="net45" />
<package id="AWSSDK.S3" version="3.7.5" targetFramework="net45" />
<package id="EntityFramework" version="6.4.4" targetFramework="net45" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
<package id="SQLite.CodeFirst" version="1.7.0.34" targetFramework="net45" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.5" targetFramework="net45" />
<package id="System.Data.SQLite" version="1.0.115.5" targetFramework="net45" />

Loading…
Cancel
Save