转换方式如下图:直接GET请求下抖音分享链接即可。
注意:需要禁止重定向。
在返回的内容处,可以获取用户的sec_uid(MS开头)
VB.NET 实现代码:
Imports System.Net
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(TextBox1.Text), HttpWebRequest)
request.AllowAutoRedirect = False
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim responseStream As System.IO.Stream = response.GetResponseStream()
Dim reader As New System.IO.StreamReader(responseStream)
Dim responseContent As String = reader.ReadToEnd()
Dim sec_uid As String = ""
' 使用正则表达式提取sec_user_id
Dim regex As New Regex("sec_uid=(.*?)&")
Dim match As Match = regex.Match(responseContent)
If match.Success Then
Dim secUserId As String = match.Groups(1).Value
sec_uid = secUserId
Else '没有找到,寻找第二种
Dim regex1 As New Regex("sec_user_id=(.*?)&") '更换正则表达式
Dim match1 As Match = regex1.Match(responseContent)
If match1.Success Then
Dim secUserId As String = match1.Groups(1).Value
sec_uid = secUserId
End If
End If
If sec_uid = "" Then
MessageBox.Show("未找到相符的sec_uid", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("sec_uid为:" & sec_uid)
End If
' 关闭资源
reader.Close()
responseStream.Close()
response.Close()
End Sub
End Class
测试结果:
软件成品,仅供测试。
抖音链接转换SEC.rar