Problem with HTTPWebrequest {Invalid URI: The URI scheme is not valid.}

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi there,

Im trying for 1 hour to fix this annoying error but it wont work.
Every time when i try to make a HTTP Web Request [POST] it gives me this error "Invalid URI: The URI scheme is not valid."

Just watch the source and youll understand.


Image:
<img alt="" src="http://i.imgur.com/ypxLT.png

It works perfectly when i do this:<br/>

<pre class="prettyprint lang-vb" style=" Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create (http://www.mywebsite.com/) , HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = "http://www.google.com/"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"

Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Close()
Dim postresponse As HttpWebResponse

postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

Dim thepage As String = postreqreader.ReadToEnd[/code]
<br/>
<br/>

But it gives me an error when i do this: (The Listbox item and Textbox containing a simple url like this: http://www.mywebsite.com/)
<pre class="prettyprint lang-vb" style=" Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create (ListBox1.SelectedItem + "index.php?q=" + TextBox1.Text + "&hl=2e5") , HttpWebRequest)<br/> postReq.Method = "POST"<br/> postReq.KeepAlive = True<br/> postReq.ContentType = "application/x-www-form-urlencoded"<br/> postReq.Referer = "http://www.google.com/"<br/> postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"<br/><br/> Dim postreqstream As Stream = postReq.GetRequestStream()<br/> postreqstream.Close()<br/> Dim postresponse As HttpWebResponse<br/><br/> postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)<br/> Dim postreqreader As New StreamReader(postresponse.GetResponseStream())<br/><br/> Dim thepage As String = postreqreader.ReadToEnd [/code]
<br/>


I hope someone can help me out with fixing this.
Thanks in advance!!
<br/>
<br/>

View the full article
 
Back
Top