Sinisterly
Askfm httpwebrequest - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: Askfm httpwebrequest (/Thread-Askfm-httpwebrequest)



Askfm httpwebrequest - tuttomax - 08-16-2013

[code=vbnet]
Private Function GetToken() As String
Dim Token As String = String.Empty
Using Web As New WebClient
Dim source As String = Web.DownloadString(String.Format("http://ask.fm/AlessandroAfo"))
Dim Regex As New Regex("(?=var AUTH_TOKEN).*")
Token = Regex.Matches(source)(0).Value.Replace("var AUTH_TOKEN = """, "").Replace(""";", "")
End Using
Return Token
End Function

Private Function Domanda(ByVal qustion As String) As String
Dim token As String = GetToken()
If String.IsNullOrEmpty(token) Then Throw New Exception("Token vuoto")
Dim data As String = String.Format("authenticity_token={0}&question%5Bquestion_text%5D={1}%3F&question%5Bforce_anonymous%5D=&authenticity_token={0}", token, qustion)
Dim bytes() As Byte = New UTF8Encoding().GetBytes(data)

Dim Request As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://ask.fm/AlessandroAfo/questions/create"), HttpWebRequest)
Request.KeepAlive = True
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Request.Referer = "http://ask.fm/AlessandroAfo"
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"

Request.Headers.Add("Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3")
Request.Host = "ask.fm"

Request.ContentLength = bytes.Length

Using [Stream] As Stream = Request.GetRequestStream
[Stream].Write(bytes, 0, bytes.Length)
End Using

Using Response As HttpWebResponse = Request.GetResponse
Using Stream As Stream = Response.GetResponseStream
Using Reader As New StreamReader(Stream)
Return Reader.ReadToEnd
End Using
End Using
End Using

End Function
[/code]
this is mycode but this is the response
[Image: d54a87af882c51e80358c961c57b47a4.png]


RE: Askfm httpwebrequest - Xanii - 08-16-2013

This was posted in the wrong section and has been moved. Please be mindful of where you are posting.



What exactly are you trying to do, and what is the problem you are experiencing?


RE: Askfm httpwebrequest - tuttomax - 08-16-2013

thanks
i'm trying to send a question to ask with httpwebrequest but the response must be a html with a text Question sent or similar thing

p.s.: sorry for bad english


RE: Askfm httpwebrequest - Xanii - 08-16-2013

I'm sorry, I can't really understand your question. Can you send me an example response you are trying to receive?


RE: Askfm httpwebrequest - tuttomax - 08-16-2013

this:
[Image: 5e48be80f092e53076bb216be9b4eb74.png]


RE: Askfm httpwebrequest - Shebang - 08-16-2013

Why is this in PHP discussion? His code is VB.Net.


RE: Askfm httpwebrequest - -Correct - 08-16-2013

I'll be asking a staff member to move this thread in few seconds.


RE: Askfm httpwebrequest - tuttomax - 08-17-2013

i resolve i insert allowredirect Smile how i close?


RE: Askfm httpwebrequest - Xiledcore - 08-17-2013

Since you requested a close, this thread is now closed. Smile