public static async Task<string> SendData3(string URL, string jsonParam)
{
string result = "";
string URLToken = $"https://192.168.111.111:1111/BSAPI/V1/ProductionData/getToken?machineNO=sponge01&key=28853ACB-FA6A-47A5-9B22-9578880290BD";
string Token = await testGetToken(URLToken, "");
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = delegate { return true; };
using (var client = new HttpClient(handler))
{
var request = new HttpRequestMessage(HttpMethod.Post, URL);
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Token);
request.Content = new StringContent(jsonParam, Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
result = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseContent);
}
return result;
}
发送json参数数据
/// <summary>
/// 发送数据
/// </summary>
/// <returns></returns>
[HttpPost(Name = "SendData")]
public async Task<string> SendData()
{
string jsonparam = "{\"destination\": \"test\",\"sourceData\": \"stri\",\"dateYear\": \"2025\", \"dateMonth\": \"11\", \"dateDay\": \"25\", \"dateHour\": \"22\", \"dateMin\": \"22\", \"dateSec\": \"22\", \"machineNo\": \"st\", \"spare01\": \"st\", \"spare02\": \"stri\", \"objectiveMachineNo1\": \"string\", \"barcode\": \"strings\", \"processNo\": \"st\", \"tireSizeNotation\": \"string\", \"productType\": \"st\", \"tireOuterDiameter\": \"stri\", \"tireInnerDiameter\": \"stri\", \"tireWidth\": \"stri\", \"beadToBeadWidth\": \"stri\", \"spongeLength\": \"st\", \"spongeWidth\": \"st\", \"spongeHeight\": \"st\", \"connectorWidth\": \"st\", \"spare03\": \"stri\", \"spare04\": \"stri\", \"spare05\": \"stri\", \"spare06\": \"stri\", \"cameraLoadXPos\": \"stri\", \"cameraLoadYPos\": \"stri\", \"cameraLoadZPos\": \"stri\", \"cameraInputPos\": \"stri\", \"tireRotatingSpeed\": \"stri\", \"spare07\": \"stri\", \"spare08\": \"stri\", \"spare09\": \"stri\", \"upperLimitValueOfSpongeHeight\": \"st\", \"lowerLimitValueOfSpongeHeight\": \"st\", \"upperLimitOfSpongeGapWidth\": \"st\", \"lowerLimitOfSpongeGapWidth\": \"st\", \"upperLimitOfSpongeAttachmentCenterOffset\": \"st\", \"lowerLimitOfSpongeAttachmentCenterOffset\": \"st\", \"snakeShapedUpperLimit\": \"st\", \"upperLimitOfSegmentDifference\": \"st\", \"spare10\": \"st\", \"spare11\": \"st\", \"spare12\": \"stri\", \"objectiveMachineNo2\": \"string\", \"barcode2\": \"string\", \"processNo2\": \"st\", \"tireSizeNotation2\": \"string\", \"productType2\": \"st\", \"cameraLoadXPos2\": \"stri\", \"cameraLoadYPos2\": \"stri\", \"cameraLoadZPos2\": \"stri\", \"cameraInputPos2\": \"stri\", \"tireRotatingSpeed2\": \"stri\", \"wrinkleStripeDetectionResults\": \"st\", \"averageSpongeHeight\": \"st\", \"spongeHeightDeterminationResult\": \"st\", \"spongeGapWidth\": \"st\", \"spongeGapWidthDeterminationResult\": \"st\", \"maximumSpongeCenterOffset\": \"st\", \"spongeCenterOffsetDeterminationResult\": \"st\", \"spongeSnakeOffset\": \"st\", \"spongeSnakeShapedOffsetDeterminationResult\": \"st\", \"spongeSegmentDifference\": \"st\", \"spongeSegmentDifferenceResult\": \"st\", \"overallJudgmentResult\": \"0\", \"spare13\": \"st\", \"spare14\": \"st\", \"tireReception\": \"st\", \"tireFixationTireClawsRising\": \"st\", \"tireFixationTireClawsextended\": \"st\", \"cameraDescentZdirection1\": \"st\", \"cameraLateralMoveXdirection1\": \"st\", \"cameraLateralMoveYdirection1\": \"st\", \"tireRotationDetection\": \"st\", \"cameraLateralMoveYdirection2\": \"st\", \"cameraLateralMoveXdirection2\": \"st\", \"cameraDescentZdirection2\": \"st\", \"tireFixationTireClawsRising2\": \"st\", \"tireFixationTireClawsDown\": \"st\", \"tireOut\": \"st\", \"totalTime\": \"st\", \"spare15\": \"st\", \"spare16\": \"st\", \"spare17\": \"st\"}";
string URL = $"https://192.168.65.48:6001/BSAPI/V1/ProductionData/SendData";
string result = await HttpClientHelper.SendData3(URL, jsonparam);
return result;
}