west555
Senior Member
- Dec 4, 2011
- 1,004
- 455
Am trying to translate text on deepl.com via HTTP requests and I fail to set cookies and I need to be logged in, in order to bypass the character limit ( I pay for pro package on deepl )
i have made the cookie and set its value but i don't know how to add it to the request to be used.
All the examples i find on the internet are not helpful in my case
here is my code so if anyone can help I would appreciate it
i have made the cookie and set its value but i don't know how to add it to the request to be used.
All the examples i find on the internet are not helpful in my case
here is my code so if anyone can help I would appreciate it
Try
Dim oCookies As CookieContainer = New CookieContainer()
Dim cookie As New HttpCookie("UserName")
cookie.Value = " Value of my cookie from live headers addon on firefox"
Dim PageSource As String = String.Empty
Dim Request As HttpWebRequest = HttpWebRequest.Create("https://api.deepl.com/jsonrpc?method=LMT_handle_jobs")
Request.Host = "api.deepl.com"
Request.Timeout = System.Threading.Timeout.Infinite
Request.KeepAlive = True
Request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0"
Request.ProtocolVersion = HttpVersion.Version11
Request.Method = WebRequestMethods.Http.Post
Request.CookieContainer = oCookies
Request.ContentType = "application/json;charset=utf-8"
Request.Referer = "https://www.deepl.com/"
Request.Accept = "application/json, text/plain, */*"
Dim post As String = "My post data"
Request.ContentLength = post.Length
Dim writer As New StreamWriter(Request.GetRequestStream)
writer.Write(post)
writer.Close()
Dim Response As HttpWebResponse = Request.GetResponse()
Dim reader As New StreamReader(Response.GetResponseStream())
PageSource = reader.ReadToEnd()
Response.Close()
If PageSource.Contains("gpt_generations") Then
Dim Paraphrased As String = PageSource
Else
End If
Catch ex As Exception
If ex.ToString.Contains("to many requests") Then
MsgBox("TO MANY REQUESTS EXITING ON : " & fName)
Exit Sub
Else
End If
Finally