asp.net开发微信公众平台通过接口上传图片到微信服务器后台,就要代码。
ASCIIEncoding encodings = new ASCIIEncoding();
HttpWebResponse webResponses = null;
string s = zone.Substring(0, zone.Length - 1);
s = s.Substring(1, s.Length - 1);
string imgurl = picssss.PostedFile.FileName;
HttpWebRequest webRequests = (HttpWebRequest)WebRequest.Create("https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=" + s );
//使用post方式提交
webRequests.Method = "POST";
string responseStrs = null;
webRequests.Timeout = 50000;
//要post的字节数组
string postDatas = "";
//?grant_type=client_credential&appid=wx875bfe9a60fc304f&secret=4e6180a6cd8e1425918ecf7cb22c36e9
byte[] postBytess = encodings.GetBytes(postDatas);
webRequests.ContentType = "application/x-www-form-urlencoded;";
webRequests.ContentLength = postBytess.Length;
using (Stream reqStream = webRequests.GetRequestStream())
{
reqStream.Write(postBytess, 0, postBytess.Length);
}
try
{
//尝试获得要请求的URL的返回消息
webResponses = (HttpWebResponse)webRequests.GetResponse();
}
catch (Exception)
{
//出错后直接抛出
throw;
}
finally
{
if (webResponses != null)
{
//获得网络响应流
using (StreamReader responseReader = new StreamReader(webResponses.GetResponseStream(), encodings))
{
responseStrs = responseReader.ReadToEnd();//获得返回流中的内容
}
webResponses.Close();//关闭web响应流
}
}
//JObject jos = (JObject)JsonConvert.DeserializeObject(responseStrs);
//string zones = jos["url"].ToString();
Response.Write(responseStrs);
return responseStrs;
}
或者帮着改改这个代码 我不知道哪里图片改写哪里,菜鸟一个 求大神出手啊。