Simulate submitting a form in web form in window form

Source: Internet
Author: User

Simulate submitting a form in web form in window form

Below is a normal form submission without File Upload!

 

Public   Function postdate () Function Postdate ( Byval URL As   String , Byval Postdata () As   String ) As   String
Dim Post As   String   =   " "
For   Each S As   String   In Postdata
Post + = S +   " &"
Next
Post = Post. substring ( 0 , Post. Length -   1 )
Dim Html As   String   =   " "

Dim Encoding As Encoding = Encoding. getencoding ( " Gb2312 " )
Dim Data As   Byte () = Encoding. getbytes (post)
Dim Myrequest As Httpwebrequest =   Ctype (Webrequest. Create (URL), httpwebrequest)
Myrequest. Method =   " Post"
Myrequest. contenttype =   " Application/X-WWW-form-urlencoded"


Myrequest. contentlength = Data. Length
Dim Newstream As Stream = Myrequest. getrequeststream ()
Newstream. Write (Data, 0 , Data. length)
Newstream. Close ()
Dim Resp As Httpwebresponse =   Ctype (Myrequest. getresponse (), httpwebresponse)
Dim Sr As Streamreader =   New Streamreader (resp. getresponsestream (), system. Text. encoding. Default )
Html = Sr. readtoend ()

Return Html
End Function

Usage:
Dim postdata as string () = {"id = luajiu", "PW = XXXX", "ipmask = 0 "}

Dim strurl as string = "http://bbs.cau.edu.cn/wusetu.cn/bbslogin"

Dim sessionhtml as string = postdate (strurl, postdata)

Files uploaded

 

 

Dim Mywebclient As   New WebClient
Dim Responsearray As   Byte () = Mywebclient. uploadfile (uristring, " Post " , Filename)
Dim Html As   String = Encoding. Default . Getstring (responsearray)

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.