Results 1 to 2 of 2

Thread: HTTP Webrequest post Inside HTTP Webrequest post

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    9

    HTTP Webrequest post Inside HTTP Webrequest post

    Im trying to create a software which can post into yahoogroups.

    I've done trying to log in yahoomail but my problem is when I am going to post in yahoogroups, I am turning back in to yahoo log in page.

    Here's my code so far:

    Imports System.IO
    Imports System.Net
    Imports System.Text
    Imports System.Text.RegularExpressions

    Public Class Form1

    Dim loginCoockie As New CookieContainer
    Dim thread As System.Threading.Thread
    Public Sub PostTopic()

    Dim yGroups As String = txtGroup.Text
    Dim TopicSubject As String = txtSubject.Text
    Dim TopicBody As String = RichTextBox1.Text

    Try

    Dim postTopic As String = "referer=%2Fgroup%2F" & yGroups & "%2F&messageNum=0&ycb=nu3Ar2AKlrH&send=Send&from=&subject=" & TopicSubject & "&message=" & TopicBody & "&lang=00"
    Dim tempCookies As New CookieContainer
    Dim encoding As New UTF8Encoding
    Dim byteData As Byte() = encoding.GetBytes(postTopic)

    Dim postRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://groups.yahoo.com/group/post" & yGroups & "z/post"), HttpWebRequest)
    postRequest.Method = "POST"
    postRequest.KeepAlive = True
    postRequest.CookieContainer = tempCookies
    postRequest.ContentType = "application/x-www-form-urlencoded"
    postRequest.Referer = "http://groups.yahoo.com/group/post" & yGroups & "/post"
    postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2"
    postRequest.ContentLength = byteData.Length

    Dim postReqStream As Stream = postRequest.GetRequestStream
    postReqStream.Write(byteData, 0, byteData.Length)
    postReqStream.Close()

    Dim postResponse As HttpWebResponse

    postResponse = DirectCast(postRequest.GetResponse(), HttpWebResponse)
    tempCookies.Add(postResponse.Cookies)
    loginCoockie = tempCookies

    Dim postReqReader As New StreamReader(postResponse.GetResponseStream())

    Dim thepage As String = postReqReader.ReadToEnd

    RichTextBox1.Text = thepage

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End Sub


    Public Sub PostThread()

    lblStatus.Text = "Trying to login"

    Dim uName As String = TextBox1.Text
    Dim pWord As String = TextBox2.Text

    Try

    Dim postData As String = ".tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=7jebrpt78q79h&.v=0& .challenge=a5PSc8KUgQ7.sU0VVUE9JsdHOosB&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.don e=http%3A%2F%2Fmail.yahoo.com&.pd=ym_ver%3D0%26c%3D%26ivt%3D%26sg%3D&.ws=1&.cp=0&pad=5&aad=6&login=" & uName & "&passwd=" & pWord & "&.save=&passwd_raw="
    Dim tempCookies As New CookieContainer
    Dim encoding As New UTF8Encoding
    Dim byteData As Byte() = encoding.GetBytes(postData)

    Dim postRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://login.yahoo.com/config/login"), HttpWebRequest)
    postRequest.Method = "POST"
    postRequest.KeepAlive = True
    postRequest.CookieContainer = tempCookies
    postRequest.ContentType = "application/x-www-form-urlencoded"
    postRequest.Referer = "https://login.yahoo.com/config/login"
    postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2"
    postRequest.ContentLength = byteData.Length

    Dim postReqStream As Stream = postRequest.GetRequestStream
    postReqStream.Write(byteData, 0, byteData.Length)
    postReqStream.Close()

    Dim postResponse As HttpWebResponse

    postResponse = DirectCast(postRequest.GetResponse(), HttpWebResponse)
    tempCookies.Add(postResponse.Cookies)
    loginCoockie = tempCookies

    Dim postReqReader As New StreamReader(postResponse.GetResponseStream())

    Dim thepage As String = postReqReader.ReadToEnd

    If thepage.Contains(Chr(34) & "status" & Chr(34) & " : " & Chr(34) & "error" & Chr(34)) = True Then
    lblStatus.Text = "Login Failed"
    Exit Sub

    Else

    lblStatus.Text = "Login success"


    End If

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    thread = New System.Threading.Thread(AddressOf PostThread)
    thread.Start()

    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Control.CheckForIllegalCrossThreadCalls = False
    End Sub
    End Class

  2. #2
    Lively Member
    Join Date
    Sep 2011
    Posts
    99

    Re: HTTP Webrequest post Inside HTTP Webrequest post

    In my own opinion, you can strip down all links first once you haved logged in.
    you need to have 2 textbox for username and password + 1 button and 1 web browser control

    then you can follow this.
    Code:
                        Dim user1 As HtmlElement = wbTS1.Document.All.Item("username")
                        user1.InnerText = txtTSusername.Text
                        Dim pass1 As HtmlElement = wbTS1.Document.All.Item("passwd")
                        pass1.InnerText = txtTSpass.Text
                        wbTS1.Document.GetElementById(".save").InvokeMember("click") 'i guess its .save for yahoomail?
    
    Dim tempList As New ListBox 'or load it really on a listbox, in my case, i just load it on an imaginary container
    
                        For Each myLink As HtmlElement In wbTS1.Document.Links
                            tempList.Items.Add(myLink.GetAttribute("HREF").ToString)
                        Next
    
    
    
    
    'after storing it on a container you can see the links where you want to go.
    'i'm pretty sure that link is on a static location like for example in my case
    
    WebBrowser1.Navigate(tempList.Items(5).ToString)
    
    'coz I know its really on the 5th location of a container
    hope that help you..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width