Error: Error 1 Cannot implicitly convert type 'System.Net.WebRequest' to 'System.Net.HttpWebRequest'. An explicit conversion exists (are you missing a cast?)
Error 2 Cannot implicitly convert type 'System.Net.WebResponse' to 'System.Net.HttpWebResponse'. An explicit conversion exists (are you missing a cast?)
nijhawan.sau...
All-Star
16400 Points
3173 Posts
Re: try to help
Apr 30, 2012 06:42 AM|LINK
Well can you paste in the code and aspx file here.
maddyrafi897...
Member
134 Points
300 Posts
Re: try to help
Apr 30, 2012 06:45 AM|LINK
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
partial class _Default1 :System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strURL = null;
string strResult = null;
HttpWebRequest wbrq = null;
HttpWebResponse wbrs = null;
StreamReader sr = null;
// Set the URL (and add any querystring values)
strURL ="http://aspnetlibrary.com/articles.aspx?Page=1";
// Create the web request
wbrq =WebRequest.Create(strURL);
wbrq.Method ="GET";
// Read the returned data
wbrs = wbrq.GetResponse();
sr =new StreamReader(wbrs.GetResponseStream());
strResult = sr.ReadToEnd().Trim();
sr.Close();
// Write the returned data out to the page
TextBox1.Text = strResult;
}
public Default1()
{
Load += Page_Load;
}
}
maddyrafi897...
Member
134 Points
300 Posts
Re: try to help
Apr 30, 2012 07:09 AM|LINK
Error: Error 1 Cannot implicitly convert type 'System.Net.WebRequest' to 'System.Net.HttpWebRequest'. An explicit conversion exists (are you missing a cast?)
Error 2 Cannot implicitly convert type 'System.Net.WebResponse' to 'System.Net.HttpWebResponse'. An explicit conversion exists (are you missing a cast?)
wbrq =WebRequest.Create(strURL);
wbrs = wbrq.GetResponse();
These 2 lines error i am getting like this...
nijhawan.sau...
All-Star
16400 Points
3173 Posts
Re: try to help
Apr 30, 2012 07:20 AM|LINK
Can you Try this:
WebRequest wbrq = null;
WebResponse wbrs = null;
But ideally WebRequest.Create(strURL); returns HttpWebRequest is url is a http one.
maddyrafi897...
Member
134 Points
300 Posts
Re: try to help
Apr 30, 2012 07:27 AM|LINK
What i want to change ?
i put like this
HttpWebRequest
wbrq = null;
HttpWebResponse wbrs = null;
StreamReader sr = null;
WebRequest.Create(strURL); still error i try all ways...
nijhawan.sau...
All-Star
16400 Points
3173 Posts
Re: try to help
Apr 30, 2012 09:22 AM|LINK
Instead of this:
HttpWebRequest wbrq = null;
HttpWebResponse wbrs = null;
Use
WebRequest wbrq = null;
WebResponse wbrs = null;
maddyrafi897...
Member
134 Points
300 Posts
Re: try to help
Apr 30, 2012 09:40 AM|LINK
There is no error in my codings but it shows null error in ym codings object reference error ? what i do ?
error occurs in this line
sr =new StreamReader(wbrs.GetResponseStream());