接口:https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=19_9
语言:C#(DotNetCore2.2)
使用MultipartFormDataContent
var mulFormDataContent = new MultipartFormDataContent("7db1851cd1158");
foreach (var item in sortedDic)
{
var sContent = new ByteArrayContent(Encoding.UTF8.GetBytes(item.Value));
sContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = $"\"{item.Key}\"",
};
mulFormDataContent.Add(sContent);
}
var byteArrayContent = new ByteArrayContent(picRequest.ImageBytes);
byteArrayContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "\"media\"",
FileName = $"\"{picRequest.ImageName}\"",
};
byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
byteArrayContent.Headers.ContentLength = picRequest.ImageBytes.Length;
mulFormDataContent.Add(byteArrayContent);
return mulFormDataContent;
最后结果:
<xml><return_code><![CDATA[FAIL]]></return_code>
<return_msg><![CDATA[参数填写有误,请检查后重试]]></return_msg>
</xml>
已经解决
https://blog.csdn.net/e5354966xieo1/article/details/103752743