说在前面
新浪图床是利用微博的接口上传到 sina 的服务器,自带全球 cdn 且没有流量限制,永久使用,已经稳定运行 5 年以上,成为站长的可靠选择。
防盗链检测
https://tva1.sinaimg.cn/large/005Q9Qt9gy1gt8l8fb88aj613z0p079b02.jpg
https://tva2.sinaimg.cn/large/005Q9Qt9gy1gt8l8fb88aj613z0p079b02.jpg
https://i0.hdslb.com/bfs/album/ef3c9a498dca6ec16eef5cc84ab441905657376f.jpg
图片尺寸
图片尺寸可供选择:square、thumb150、orj360、orj480、mw690、mw1024、mw2048、small、bmiddle、large
Cookie
请求携带的 Cookie,是需要 SUB
即可
1
| SUB=_2A25MCvP_DeRhGeNN7lMS-C7OzDWIHXVv9J23rDV6PUJbktB-LW79kW1NSZalCW3YlWBr9ppYz3o26-OycVDHbTcP
|
校验 Cookie
1 2 3 4 5 6 7 8 9 10 11 12 13
| var url = "https://rm.api.weibo.com/2/remind/push_count.json?with_push_settings=1&trim_null=1&with_dm_group=0&with_settings=1&exclude_attitude=1&with_common_cmt=1&with_comment_attitude=1&with_common_attitude=1&with_moments=1&with_dm_unread=1&msgbox=true&with_page_group=1&with_chat_group=1&with_chat_group_notice=1&_pid=1&count=4&source=351354573&status_type=0&callback=STK_162834008316744"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET"; request.Headers.Add("Cookie", "SUB=_2A25MCvP_DeRhGeNN7lMS-C7OzDWIHXVv9J23rDV6PUJbktB-LW79kW1NSZalCW3YlWBr9ppYz3o26-OycVDHbTcP"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var str = reader.ReadToEnd(); Console.WriteLine(str);
return str; }
|
校验成功样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| try { STK_162834008316744({ code: 1, data: { dm_unread: 1, dm: 1, message_flow_unaggregate: 1, pc_viedo: 1, status_24unread: 100, message_flow_unaggr_wild_card: 21, message_flow_follow: 22, double_flow: 30, dm_pc: 24, dm_total: 24, msgbox_schemeitem: 1, remind_settings: {}, status: 2, app_message: [], total_unread: 1, messages: 24, push_settings: { groupchatNotifyReceive: 2, groupchatNotifyPush: 2 }, }, }); } catch (e) {}
|
图片上传-Base64
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| var url = "https://picupload.weibo.com/interface/pic_upload.php?data=base64&p=1"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST"; request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundaryamXBwD6LQvBO5bnb"; request.Headers.Add("Cookie", "SUB=_2A25MCvP-DeRhGeNN7lMS-C7OzDWIHXVv9J22rDV_PUNbm9B-LXbHkW1NSZalCYNoeEZs8JG77NgUsmQin2r2c5EZ");
using (Stream stream = request.GetRequestStream()) { var data = @"------WebKitFormBoundaryamXBwD6LQvBO5bnb Content-Disposition: form-data; name=""b64_data""
/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9ZKKKK/TD8fP/2Q== ------WebKitFormBoundaryamXBwD6LQvBO5bnb-- "; byte[] trailer = Encoding.ASCII.GetBytes(data); stream.Write(trailer, 0, trailer.Length);
stream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var str = reader.ReadToEnd(); Console.WriteLine(str);
return str; }
|
输出样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "code": "A00006", "data": { "count": 1, "data": "eyJ1aWQiOjUzNTEzODAyNzksImFwcCI6Im1pbmlibG9nIiwiY291bnQiOjEsInRpbWUiOjE2MjgzNDU4MDYuMjU0LCJwaWNzIjp7InBpY18xIjp7IndpZHRoIjoxLCJzaXplIjoyODgsInJldCI6MSwiaGVpZ2h0IjoxLCJuYW1lIjoicGljXzEiLCJwaWQiOiIwMDVROVF0OWd5MWd0OGwzaWZxYzRqMzAwMTAwMTA4MCJ9fX0=", "pics": { "pic_1": { "width": 1, "size": 288, "ret": 1, "height": 1, "name": "pic_1", "pid": "005Q9Qt9gy1gt8l3ifqc4j3001001080" } } } }
|
图片上传-二进制流
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| var url = "https://picupload.weibo.com/interface/pic_upload.php?data=1&p=1"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST"; request.ContentType = "multipart/form-data"; request.Headers.Add("Cookie", "SUB=_2A25MCvP-DeRhGeNN7lMS-C7OzDWIHXVv9J22rDV_PUNbm9B-LXbHkW1NSZalCYNoeEZs8JG77NgUsmQin2r2c5EZ");
using (Stream stream = request.GetRequestStream()) { FileStream fsRead = new FileStream(@"test.jpg", FileMode.Open); int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; fsRead.Read(heByte, 0, heByte.Length); fsRead.Close(); fsRead.Dispose(); stream.Write(heByte, 0, heByte.Length);
stream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var str = reader.ReadToEnd(); Console.WriteLine(str);
return str; }
|
输出样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| { "code": "A00006", "data": { "count": 1, "data": "eyJ1aWQiOjUzNTEzODAyNzksImFwcCI6Im1pbmlibG9nIiwiY291bnQiOjEsInRpbWUiOjE2MjgzNDU4OTAuMjU5LCJwaWNzIjp7InBpY18xIjp7IndpZHRoIjoyLCJzaXplIjoyOTIsInJldCI6MSwiaGVpZ2h0IjoxLCJuYW1lIjoicGljXzEiLCJwaWQiOiIwMDVROVF0OWd5MWd0OGw0eXZ1NGFqMzAwMjAwMTA4NCJ9fX0=", "pics": { "pic_1": { "width": 2, "size": 292, "ret": 1, "height": 1, "name": "pic_1", "pid": "005Q9Qt9gy1gt8l4yvu4aj3002001084" } } } }
|