Last post Apr 01, 2015 10:15 AM by mdivk
Mar 31, 2015 08:47 AM|mdivk|LINK
I want to mock up a button click event and passing a postdata using WebRequest, here is my code:
Dim req As WebRequest = WebRequest.Create(site)
Dim postData As String = "ctl00$TemplateBody$WebPartManager1$gwpciPublicRegistry$ciPublicRegistry$ResultsGrid$Sheet0$Input1$TextBox1=a"
Dim send As Byte() = Encoding.[Default].GetBytes(postData)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = send.Length
Dim sout As Stream = req.GetRequestStream()
sout.Write(send, 0, send.Length)
Dim res As WebResponse = req.GetResponse()
The code returns error in the last line above:
The remote server returned an error: (503) Server Unavailable.
Here is the site's URL:
What I want to do is to mockup TextBox1 has a value of "a" and then the button is clicked.
It would be appreciated if anyone can point out what's wrong with my code?
Apr 01, 2015 02:37 AM|Zhi Lv - MSFT|LINK
According to your code and description, I have created a sample in my side, the result as below:
// Create a request using a URL that can receive a post.
// WebRequest request = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx"); //Worked well
// WebRequest request = WebRequest.Create("http://10.168.176.22/testWinformdll/WebForm1.aspx"); //Worded well
WebRequest request = WebRequest.Create("http://ctcma.asicanada.net/CTCMAmbr/Public_Registry.aspx"); // Throw The remote server returned an error: (503) Server Unavailable.
So, I suppose the issue is related to the remote server.
You could refer to this article:
Besides, here are some similar thread and relevant article, please refer to it.
remote server returned an error: (503) Server Unavailable Asp.Net
How to: Send Data Using the WebRequest Class
Apr 01, 2015 10:15 AM|mdivk|LINK
Reading https://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx, I have a question:
if the remote website has a textbox with the id of txtKeyword, and a search button
How do I (in my code) passing a value to txtKeyword and send the request to the website and get response?
Can you show me how to write the code?
Thank you very much.