当前位置:网站首页>C# 微信上传Form-data
C# 微信上传Form-data
2022-06-11 07:39:00 【千金少】
微信小程序审核有时候要做图片上传验证 使用的还是from-data格式,非常的坑爹
官方文档讲的一点也不清楚
请求地址:
https://api.weixin.qq.com/wxa/uploadmedia?access_token=ACCESS_TOKEN
这里有几个坑爹的地方在做上传的时候,经常会报errmsg=media data missing rid: 629f1365-2b583ac9-3f11b616,经过一下午的测试后终于找出了原因。httpClient会自动将boundary自动加上双引号,导致调用失败。所以需要手动处理掉

最后直接附上C#上传的代码
public async Task<string> AccessFormData(string url, HttpPostedFileBase file, string key)
{
var httpClient = new HttpClient();
var content = new MultipartFormDataContent();
var boundaryValue = content.Headers.ContentType.Parameters.Single(p => p.Name == "boundary");
boundaryValue.Value = boundaryValue.Value.Replace("\"", string.Empty);
if (file?.InputStream != null)
{
content.Add(new StreamContent(file.InputStream, (int) file.InputStream.Length), $"\"{key}\"",
$"\"{file.FileName}\"");
var response = await httpClient.PostAsync(url, content);
return await response.Content.ReadAsStringAsync();
}
return string.Empty;
}这里的key就是那个media
边栏推荐
- [IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
- Implementation of stack (C language)
- Simple configuration of vscade
- Sqlzoo question brushing record-3
- Nim product
- [atcoder2000] leftmost ball (dp+ combination number)
- 2022 low voltage electrician test questions and online simulation test
- 2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
- 2022低压电工操作证考试题模拟考试平台操作
- Sdl-4 PCM playback
猜你喜欢

Paging of the flask page

3年功能测试拿8K,被新来的反超,其实你在假装努力
![[analysis of STL source code] summary note (4): behind the scenes hero allocator](/img/b9/cf53fd8f933042ff65844d61eca55e.jpg)
[analysis of STL source code] summary note (4): behind the scenes hero allocator

QT picture adaptive display control

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
![[codeforces1019e] raining season](/img/8e/4a96954ee7dae5f81eaae05b5a075b.png)
[codeforces1019e] raining season
![20200727 T2 small w playing game [generating function (binomial inversion technique)]](/img/a5/ae2192f4f37232cdcb01e81ad0297c.jpg)
20200727 T2 small w playing game [generating function (binomial inversion technique)]
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query
![20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] &](/img/90/99356e679a52890a0b88068d082bbe.jpg)
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
随机推荐
C language volatile
[analysis of STL source code] summary notes (3): vector introduction
【软件测试】这样的简历已经刷掉了90%的面试者
Wc2020 guessing game
[atcoder1981] short diameter (graph theory thinking)
MFC debugger OutputDebugString override
Ffmpeg extraction package format extracts AAC and customizes adtc header to realize arbitrary frame decoding
JVM tuning
【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
C language inherits memory management mechanism (unfinished)
【AtCoder1984】Wide Swap (拓扑排序转化)
如何准备PMP新版大纲考试?
[Oracle database] mammy tutorial day03 Sorting Query
Aiop introduction
Bidirectional linked list simple template (pointer version)
欧拉定理及扩展(附证明)
Euler's theorem and its extension (with proof)
Seata的几种事务模式
Miscellany C language
[STL source code analysis] summary notes (7): ingenious deque