代码能上传文件获取media_id,但是推送的消息不显示文件名,不知道Content-Disposition: form-data; name="media";filename="wework.txt"; filelength=6,如何提交
参考接口文档:https://developer.work.weixin.qq.com/document/path/90871
Dim result As String = ""
url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=" & token & "&type=file"
'url是请求地址 ,data是参数
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = WebRequest.Create(url)
'设置Post请求方式
request.Method = "POST"
'参数内容类型
request.ContentType = "application/octet-stream"
Dim params = New Dictionary(Of String, String)
'将URL编码后的参数字符串转化为字节
Dim enCoding As New UTF8Encoding()
Using reader As New StreamReader("c:\x.txt", False)
result = reader.ReadToEnd()
End Using
Dim bys As Byte() = enCoding.GetBytes(result)
'Dim bys As Byte() = New UTF8Encoding(True).GetBytes(result)
'设置POST请求的 ContentLength
request.ContentLength = bys.Length
'获得请求数据流
Dim newStream As Stream = request.GetRequestStream()
newStream.Write(bys, 0, bys.Length)
newStream.Close()
'获得响应数据流
Dim requestStream = request.GetRequestStream()
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
'MsgBox(sr.ReadToEnd)
Dim rustr = sr.ReadToEnd
Dim media_id As String
'返回信息里面分解
If InStr(rustr, "media_id") > 1 Then
'MsgBox(rustr)
media_id = Split(rustr, ",")(3)
media_id = Split(media_id, ":")(1)
media_id = Replace(media_id, """", "")
Else
media_id = ""
End If
TextBox2.Text = media_id
参考接口文档:https://developer.work.weixin.qq.com/document/path/90871
Dim result As String = ""
url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=" & token & "&type=file"
'url是请求地址 ,data是参数
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = WebRequest.Create(url)
'设置Post请求方式
request.Method = "POST"
'参数内容类型
request.ContentType = "application/octet-stream"
Dim params = New Dictionary(Of String, String)
'将URL编码后的参数字符串转化为字节
Dim enCoding As New UTF8Encoding()
Using reader As New StreamReader("c:\x.txt", False)
result = reader.ReadToEnd()
End Using
Dim bys As Byte() = enCoding.GetBytes(result)
'Dim bys As Byte() = New UTF8Encoding(True).GetBytes(result)
'设置POST请求的 ContentLength
request.ContentLength = bys.Length
'获得请求数据流
Dim newStream As Stream = request.GetRequestStream()
newStream.Write(bys, 0, bys.Length)
newStream.Close()
'获得响应数据流
Dim requestStream = request.GetRequestStream()
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
'MsgBox(sr.ReadToEnd)
Dim rustr = sr.ReadToEnd
Dim media_id As String
'返回信息里面分解
If InStr(rustr, "media_id") > 1 Then
'MsgBox(rustr)
media_id = Split(rustr, ",")(3)
media_id = Split(media_id, ":")(1)
media_id = Replace(media_id, """", "")
Else
media_id = ""
End If
TextBox2.Text = media_id